## WeBWorK Problems by Joseph Lo -
Number of replies: 0
I am trying to make a problem that accepts periodic answers with units. I have attached the code of a sample question at the end.

For example, the solutions of sin(theta) = 0.5 in the first quadrant can be
I used the following to check the answer and everything works correctly.

$ansc = Real(pi/6)->with(period=>2*pi);$ans = NumberWithUnits($ansc,"rad"); ANS($ans->cmp());

On the other hand, I also want to accept
theta = 30 deg
theta = 390 deg, etc...
But the answer checker does not accept "390 deg". It instead accepts "(30 + 2*pi) deg".

For another example, the solutions of sin(at) = 0.5 when a = pi/3 rad/min can be
t = 0.5 min,
t = 6.5 min, etc... (just 1st quadrant for at for now)
The following checker works as long as the unit is in min.

$ansc = Real(0.5)->with(period=>Real(6));$ans = NumberWithUnits($ansc,"min"); ANS($ans->cmp());

But if students enter their answers in seconds, the answer checker accepts t = 30 s but also "t = 36 s". The period is changed to 6 seconds instead of 6 minutes.

Is there a way for the answer check to appropriately accept a periodic answer with unit? If I need to write a custom answer checker, how can I convert the unit of student's answer to the unit provided in the answer key? Thanks very much for any help or insight.

DOCUMENT();
"PGbasicmacros.pl",
"MathObjects.pl",
"parserNumberWithUnits.pl",
);

TEXT(beginproblem());

Context()->texStrings;
BEGIN_TEXT
Find one value of $$\theta$$ so that $$\sin(\theta) = \dfrac{1}{2}$$ and $$\cos(\theta) = \dfrac{\sqrt{3}}{2}$$. Include the \{helpLink("unit")\} in your answer.
$BR $$\theta =$$ \{ans_rule(20)\}$BR $BR Find one value of $$t$$ so that $$\sin(\omega t) = 0.5$$ and $$\cos(\omega t) = \dfrac{\sqrt{3}}{2}$$ if $$\omega = \dfrac{\pi}{3}$$ rad/min. Include the \{helpLink("unit")\} in your answer.$BR
$$t =$$ \{ans_rule(20)\}
END_TEXT
Context()->normalStrings;

$ansc = Real(pi/6)->with(period=>2*pi);$ans = NumberWithUnits($ansc,"rad"); ANS($ans->cmp());

$ansc = Real(0.5)->with(period=>Real(6));$ans = NumberWithUnits($ansc,"min"); ANS($ans->cmp());

ENDDOCUMENT();