Difference between revisions of "NamedAnswerRules"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 27: Line 27:
 
"PGstandard.pl",
 
"PGstandard.pl",
 
"MathObjects.pl",
 
"MathObjects.pl",
  +
"PGML.pl"
 
);
 
);
 
TEXT(beginproblem());
 
TEXT(beginproblem());
Line 44: Line 45:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context(".....");
 
  +
$ans = Compute(random(1, 5));
Define context and variables for the questions
 
   
$expr = Formula("....");
 
  +
$ansName = NEW_ANS_NAME();
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 67: Line 67:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
BEGIN_TEXT
 
  +
BEGIN_PGML
...... question text ......
 
  +
Enter [$ans]: [_]{$ans}{
END_TEXT
 
  +
END_PGML
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">

Revision as of 13:50, 6 May 2021

Name Answer Rules


This PG code shows how to used named answers in problems in such a way that the problem will work in both homework and gateway quizzes. 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",
"PGML.pl"
);
TEXT(beginproblem());

Initialization: The usual stuff here.

$ans = Compute(random(1, 5));

$ansName = NEW_ANS_NAME();

Setup: We specify that the Context should be ......, and define the answer to be a formula.

Notes: on using this and related Contexts.

BEGIN_PGML
Enter [$ans]: [_]{$ans}{
END_PGML

Main Text: The problem text section of the file is as we'd expect.

$showPartialCorrectAnswers = 1;

ANS( $expr->cmp() );

ENDDOCUMENT();

Answer Evaluation: As is the answer.

Problem Techniques Index