Difference between revisions of "AnswerInExponent"

From WeBWorK_wiki
Jump to navigation Jump to search
(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...)
 
m (1 revision: import all default namespace pages from old wiki)
(No difference)

Revision as of 16:19, 14 May 2010

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