## WeBWorK Problems

### "Operands of '*' can't be words"

by Siman Wong -
Number of replies: 1

I would like to make a list/array of the symbols

1, -1, i, -i, j, -j, k, -j
but webwork does not seem to like the minus signs; I keep getting the error message Operands of '*' can't be words; see position 1 of formula at line 35 of [TMPL]/PS-Cosets/cosets-problem1-1-header.pg Died within main::List called at line 35 of [TMPL]/PS-Cosets/cosets-problem1-1-header.pg If I remove the minus signs in line 35 then the codes go through...  I must have messed up the syntax somewhere; any suggestions and comments are most welcome. THANKS! p.s. could someone tell me how to force the "plain text mode" in the message editor? ----------------------------------------------------------------

DOCUMENT(); # This should be the first executable line in the problem.
"PG.pl",
"PGstandard.pl",
"MathObjects.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGauxiliaryFunctions.pl"
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1; Context()->strings->add(i=>{}); Context()->strings->add(j=>{}); Context()->strings->add("-"=>{}); Context()->strings->add(k=>{});$q = random(0,1,1);

if($q == 0){ @set = (i, j, j, "j", k, "k"); } elsif($q == 1){
@set = (i,"i", i,"i",-1, 1);
}

@ans2 = ();

for($i=2;$i<scalar(@set);$i++){ @ans2[$i-2] = $set[$i];
}

$answer2 = List($set[0], $set[1],$set[2], $set[3]); BEGIN_TEXT (ii) $$G =$$ the quaternion group $$\mathbb{Q}_{8} = LB 1, -1, i, -i, j, -j, k, -k RB$$$BR
     $$H = set[0]$$ $BR      $$g$$  $$= set[1]$$$BR $BR \{ans_rule(10)\}$BR $BR END_TEXT ANS($answer2->cmp(unordered=>1) );



ENDDOCUMENT();

### Re: "Operands of '*' can't be words"

by Gavin LaRose -
Hi Siman,

I think the problem is that there is an implied multiplication when you write -j: - is defined to be a string, and j similarly, but then -j isn't a separate string and so WeBWorK tries to multiply the two.

One solution would be to just include the -j (et al.) as strings:

Context()->strings->add(i=>{}, j=>{}, k=>{},
"-i"=>{}, "-j"=>{},
"-k"=>{});


Then I think the rest of the code will work, though there may be some less than perfect error messages (e.g., "Your second word is incorrect").

As a side note, PGstandard.pl loads PG.pl, PGbasicmacros.pl, PGanswerevaluators.pl, and PGauxiliaryFunctions.pl, so those don't need to be loaded as well as PGstandard.

Gavin