WeBWorK Main Forum

Problem using NumberWithUnits and OneOf

Problem using NumberWithUnits and OneOf

by Marc Smith -
Number of replies: 0

Hi All:

    I am writing some WeBWorK problems for engineering and need to accept numerical answers with units.  In one simple example, the student needs to compute a temperature and I would like to accept answers in either Kelvin or degree Celsius units (since these are not converted automatically).  Using the OneOf macro with the NumberWithUnits math object seems to fit this problem perfectly.  However, when I run the simple example below to enter either 300 degK or 27 degC, the problem does not accept answers with units as correct, just the numbers themselves as correct.   Am I doing something wrong here?  Thanks for any help. 

DOCUMENT();

loadMacros(

    "PGstandard.pl",

    "MathObjects.pl",

    "PGML.pl",

    "parserNumberWithUnits.pl",

    "parserOneOf.pl",

);

TEXT(beginproblem());

Context("Numeric");

$T1 = NumberWithUnits( 300, "degK" );

$T2 = NumberWithUnits(  27, "degC" );

Context()->texStrings;

BEGIN_PGML

[` T_1 = [$T1],  T_2 = [$T2] `]  

Enter either temperature:  [__]{ OneOf($T1, $T2) }  (Use units in your answer.)  

END_PGML

ENDDOCUMENT();