AnswerWithUnits1

From WeBWorK_wiki
Revision as of 01:14, 5 December 2010 by Pearson (talk | contribs) (Created page with '<h2>Answer is a Number or Formula with Units</h2> 300px|thumb|right|Click to enlarge <p style="background-color:#f9f9f9;border:black solid 1px;padd…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

  • Download file: File:AnswerWithUnits1.txt (change the file extension from txt to pg when you save it)
  • File location in NPL: FortLewis/Authoring/Templates/DiffCalc/AnswerWithUnits.pg


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT(); 

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

TEXT(beginproblem());

Initialization:

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');

$answer[0] = FormulaWithUnits("$v","ft/s");
$answer[1] = NumberWithUnits("$v1","ft/s");
$answer[2] = FormulaWithUnits("$a","ft/s^2");

Setup:

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
units in your answer.
$BR
\{ ans_rule(20) \}
\{ helpLink("units") \}
$BR
$BR
(b) What is the velocity of the object when it
hits the ground?  Include units in your answer. 
$BR
\{ ans_rule(20) \}
\{ helpLink("units") \}
$BR
$BR
(c) What is the acceleration of the object?  
Include units in your answer. 
$BR
\{ ans_rule(20) \}
\{ helpLink("units") \}
END_TEXT
Context()->normalStrings;

Main Text:

$showPartialCorrectAnswers = 1;

foreach my $i (0..2) {
  ANS( $answer[$i]->cmp() );
}

Answer Evaluation:

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:

Templates by Subject Area