Numeric Answers - PGML

From WeBWorK
(Difference between revisions)
Jump to: navigation, search
(Examples of quoted answers)
m (Add PGML Sytnax category)
Line 45: Line 45:
  
 
[[Category:PGML]]
 
[[Category:PGML]]
 +
[[Category:PGML Syntax]]
 
[[Category:PGML Answers]]
 
[[Category:PGML Answers]]

Revision as of 19:03, 11 May 2015

Numeric Answer Checkers

To use a number as an answer, just put the number in braces after the answer blank:

 BEGIN_PGML
 The value of [: 3 + 5:] is [______]{8}
 END_PGML

The value can be stored in a variable:

 $a = 3; $b = 5;
 $answer = $a + $b;
 
 BEGIN_PGML
 The value of [: [$a] + [$b]:] is [______]{$answer}
 END_PGML

or it can be an expression producing the value:

 $a = 3; $b = 5;
 
 BEGIN_PGML
 The value of [: [$a] + [$b]:] is [______]{$a+$b}
 END_PGML

The number can be a MathObject Real or Complex, or Fraction, or other numeric value as well

 $a = 3; $b = 5;
 $answer = Compute("$a + $b");
 
 BEGIN_PGML
 The value of [: [$a] + [$b]:] is [______]{$answer}
 END_PGML

It is also possible to put the number (or formula leading to the number) in quotation marks, though this isn't necessary. If you do, however, the correct answer will be shown as the formula you used rather than the numeric value itself.

 $a = 3; $b = 5;
 BEGIN_PGML
 The value of [: [$a] + [$b]:] is [______]{"$a + $b"}
 END_PGML

will show "3 + 5" as the correct answer, not 8. (Note: this requires a recent version of PGML.pl)

follow us