PREP 2015 Question Authoring - Archived

Units in PGML answer checker

Units in PGML answer checker

by Douglas Young -
Number of replies: 1
The "old" answer checker had an option to specify the units for an answer:

&ANS(num_cmp($ans1,reltol=>1,format=>'%0.4g',units=>'ohm') );

Is there a way to do this in PGML? The old answer checker was really good about "knowing" how to convert units (24 cm = 240 mm = .24 m). Will PGML use this same option?
In reply to Douglas Young

Re: Units in PGML answer checker

by Davide Cervone -
You can use any answer checkering in PGML that you could in traditional problems. For example, you could use
$cmp = num_cmp($ans1,reltol=>1,format=>'%0.4g',units=>'ohm') ;
BEGIN_PGML
The answer is [_________________]{$cmp};
END_PGML 
But you could also use the MathObject version of that by loading parserNumberWithUnits.pl and then creating a MathObject with NUmberWithUnits(). E.g.,
loadMacros("parserNumberWithUnits.pl");
$ans = NumberWithUnits($ans1,'ohm');
BEGIN_PGML
The answer is [_________________]{$ans};
END_PGML 
This uses the same library as the traditional num_cmp to do the units checking, so it should provide the same functionality as the traditional approach.