## Answer is a Number or Formula with Units

Click to enlarge

This PG code shows how to require students to enter units with their answers.

PG problem file Explanation

Problem tagging:

```DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"parserNumberWithUnits.pl",
"parserFormulaWithUnits.pl",
);

TEXT(beginproblem());
```

Initialization: We load `parserNumberWithUnits.pl` and `parserFormulaWithUnits.pl`.

```Context("Numeric")->variables->are(t=>"Real");

\$h = Formula("-16 t^2 + 16");
\$v = \$h->D('t');
\$v1 = \$v->eval(t=>1);
\$a = \$v->D('t');

```

Setup: We use the differentiation operator `->D('t')` and the evaluation method `->eval()` to construct the derivative and evaluate it as a function. If we were writing several questions like this with different height functions, using the differentiation and evaluation methods would really speed up the writing.

```Context()->texStrings;
BEGIN_TEXT
Suppose the height of a falling object, in feet
above the ground, is given by \( h(t) = \$h \)
for \( t \geq 0 \), where time is measured in
seconds.
\$BR
\$BR
(a) What is the velocity of the object?  Include
\$BR
\{ ans_rule(20) \}
\$BR
\$BR
(b) What is the velocity of the object when it
\$BR
\{ ans_rule(20) \}
\$BR
\$BR
(c) What is the acceleration of the object?
\$BR
\{ ans_rule(20) \}
END_TEXT
Context()->normalStrings;
```

Main Text: Don't forget to use `helpLink("units")` so your students will have access to the complete list of units that WeBWorK understands.

```\$showPartialCorrectAnswers = 1;

foreach my \$i (0..2) {
}
```

```Context()->texStrings;
BEGIN_SOLUTION
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();
```

Solution: