WeBWorK Problems

NumbersWithUnits

by Justin Heckman -
Number of replies: 2
Hi,

I am a high school physics teacher and I have been using WeBWorK for nearly a decade. (I set up my own server) I have been begrudgingly content with using the CAPA Physics problems until recently. I have begun authoring my own problems recently but have some questions about NumbersWithUnits.

I am wondering if a variable such as $t=NumberWithUnits("17 s"); can be used in a subsequent calculated variable. e.g.$x=NumberWithUnits("14*$t m")? I would just try it out but I am having some students reinstall the newest version of WeBWorK In reply to Justin Heckman Re: NumbersWithUnits by Michael Gage - You can try out snippets of code at https://demo.webwork.rochester.edu/webwork2/wikiExamples/MathObjectsLabs2 It works similarly to the PGML lab. It can also be reached from the PGlabs page on the wiki. http://webwork.maa.org/wiki/PGLabs (demo.webwork.rochester.edu is the replacement for hosted2.webwork.rochester.edu) Your example evaluates x as 238 s*m using this code: loadMacros("parserNumberWithUnits.pl");$t = NumberWithUnits("17 s");
$x=NumberWithUnits("14 *$t m");
$y=NumberWithUnits("2*$x ");

BEGIN_TEXT

t is $t$BR
x is $x$BR
y is $y$BR

END_TEXT