WeBWorK Problems

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

"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.

$showPartialCorrectAnswers = 1;


$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 = ();

 @ans2[$i-2] = $set[$i];

$answer2 = List($set[0], $set[1], $set[2], $set[3]);


(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


ANS( $answer2->cmp(unordered=>1) );


In reply to Siman Wong

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"=>{},

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.