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...)
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
  +
{{historical}}
  +
  +
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/AnswerInExponent.html a newer version of this problem]</p>
 
<h2>Answer Blanks in the Exponent</h2>
 
<h2>Answer Blanks in the Exponent</h2>
   

Latest revision as of 16:50, 20 June 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

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