I'm authoring a webwork problem whose solution key (i.e. the one seen by students) depends on the randomized parameter. I tried
to do that using if/then/else (see below) but GPLab gives the error
Can't find string terminator "END_SOLUTION" anywhere before EOF at (eval 2048) line 77.
I'd be most appreciative for any advice and suggestions. THANKS!
#Context()->texStrings;
if($m % 2 == 0){
SOLUTION(EV3(<<'END_SOLUTION'));
$PAR SOLUTION $PAR
(text of first case)
END_SOLUTION
}
else{
SOLUTION(EV3(<<'END_SOLUTION'));
$PAR SOLUTION $PAR
(text of second case)
END_SOLUTION
}
#Context()->normalStrings;
Hi Siman,
For some reason, Perl and / or WebWork does not like the construction if ($m %2 == 0). If you precompute the modular arithmetic $m % 2, then you should be able to get things to work as expected:
$m = random(1,10,1);
$m2 = $m % 2;
if ($m2 == 0) {
TEXT("$m even");
} else {
TEXT("$m odd");
}
Good luck!
Paul Pearson
For some reason, Perl and / or WebWork does not like the construction if ($m %2 == 0). If you precompute the modular arithmetic $m % 2, then you should be able to get things to work as expected:
$m = random(1,10,1);
$m2 = $m % 2;
if ($m2 == 0) {
TEXT("$m even");
} else {
TEXT("$m odd");
}
Good luck!
Paul Pearson
Hi Siman,
good to hear from you and to see you using WeBWorK.
The error message which you quote is often generated when the
line containing the intended end quote text (in this case "END_SOLUTION")
actually contains other characters (leading or trailing tabs and spaces are
the usual offenders).
As a matter of style, saying
BEGIN_SOLUTION
in place of
SOLUTION(EV3(<<'END_SOLUTION'));
is a nice bit of syntactic sugar which makes problems a little easier to read.
Cheers, Djun