External Answer Checkers - PGML

From WeBWorK
Jump to: navigation, search

Using ANS() with PGML

Although it is customary to provide the correct answer right for an answer blank after the blank in the PGML code, it is also possible to provide the answer later using the ANS() macro, as is done with BEGIN_TEXT/END_TEXT blocks. To do this, simply don't put any braces after the answer blank.

 loadMacros("contextLimitedNumeric.pl");
 Context("LimitedNumeric");
 $a = 3; $b = 5;
 $answer = Real($a+$b);
 
 BEGIN_PGML
 The value of [: [$a] + [$b] :] is [_______]
 END_PGML
 
 ANS($answer->cmp);

You can use all the traditional or MathObject based answer checkers this way.

If there is more than one answer blank, then the answer checkers are paired with them by order, as usual.

 Context("Numeric");
 Context()->functions->disable("sqrt");
 Context()->operators->remove("^","**");
 $a = 16; $b = 9;
 $ra = Real(sqrt($a)); $rb = Real(sqrt($b));
 
 BEGIN_PGML
 The value of [: sqrt([$a]) :] is [___________]  
 The value of [: sqrt([$b]) :] is [___________]
 END_PGML
 
 ANS(
   $ra->cmp,
   $rb->cmp
 );
follow us