AnswerInExponent

From WeBWorK_wiki
Revision as of 11:50, 19 April 2010 by Pearson (talk | contribs) (New page: <h2>Answer Blanks in the Exponent</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This P...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Answer Blanks in the Exponent


This PG code shows how to check student answers that are equations. Note that this is an insertion, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
"unionTables.pl",
);
TEXT(beginproblem());

Initialization: We need to include the macros file unionTables.pl (or PGunion.pl which also loads it).

Context("Numeric")->variables->are(a=>"Real",b=>"Real");

$n = random(3,9,1);

#  TeX
$expression = "a^{$n} b^{$n}";

#  MathObjects
$base = Formula("a*b");
$exponent = Formula("$n");

#
#  Display exponents nicely
#
$w1 = 10; # width of 1st answer blank
$w2 = 10; # width of 2nd answer blank
Context()->texStrings;
if ($displayMode eq 'TeX') {
  $showpower =
  "\( \displaystyle $expression = (" . ans_rule($w1) . ")^{" . ans_rule($w2) . "}\)";
} else {
  $showpower =
  ColumnTable(
  "\( \displaystyle $expression = \Big( \) " . ans_rule($w1) . " \( \Big) \)",
  ans_rule($w2).$BR.$BR,
  indent => 0, separation => 0, valign => "BOTTOM"
  );
}
Context()->normalStrings;

Setup: We have a little bit of code to display the answer blanks nicely in different modes.

Context()->texStrings;
BEGIN_TEXT
Rewrite the following using a single exponent.
$BR
$BR
$showpower
END_TEXT
Context()->normalStrings;

Main Text: The problem text section of the file is as we'd expect. We insert the nicely formatted answer blanks using $showpower.

$showPartialCorrectAnswers = 1;

ANS( $base->cmp() );
ANS( $exponent->cmp() );

ENDDOCUMENT(); 

Answer Evaluation: As is the answer.

Problem Techniques Index