FormulaAnswer1: Difference between revisions

From WeBWorK_wiki
Jump to navigation Jump to search
(Add link to PGML version in OPL)
(Updated this example to PGML and switched AnswerFormatHelp.pl to helpLink.)
Line 42: Line 42:
DOCUMENT();
DOCUMENT();


loadMacros(
loadMacros('PGstandard.pl','MathObjects.pl','PGML.pl');
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
);


TEXT(beginproblem());
TEXT(beginproblem());
Line 64: Line 60:
<td style="background-color:#ffffdd;border:black 1px dashed;">
<td style="background-color:#ffffdd;border:black 1px dashed;">
<pre>
<pre>
Context("Numeric");
Context('Numeric');


$a = non_zero_random(-9,9,1);
$a = non_zero_random(-9,9,1);
Line 86: Line 82:
<td style="background-color:#ffdddd;border:black 1px dashed;">
<td style="background-color:#ffdddd;border:black 1px dashed;">
<pre>
<pre>
Context()->texStrings;
BEGIN_PGML
BEGIN_TEXT
Enter [`[$answer1]`]: [____]{$answer1} [@ helpLink('number') @]*
Enter \( $answer1 \):  
 
\{ ans_rule(20) \}
Enter [`[$answer2]`]: [____]{$answer2} [@ helpLink('formula') @]*
\{ AnswerFormatHelp("numbers") \}
END_PGML
$BR
$BR
Enter \( $answer2 \):  
\{ ans_rule(20) \}
\{ AnswerFormatHelp("formulas") \}
END_TEXT
Context()->normalStrings;
</pre>
</pre>
<td style="background-color:#ffcccc;padding:7px;">
<td style="background-color:#ffcccc;padding:7px;">
<p>
<p>
<b>Main Text:</b>
<b>Main Text:</b>
</p>
</td>
</tr>


<!-- Answer evaluation section -->
* The <tt>helpLink</tt> command show some additional help for entering values. 
 
<tr valign="top">
<td style="background-color:#eeddff;border:black 1px dashed;">
<pre>
$showPartialCorrectAnswers = 1;
 
ANS( $answer1->cmp() );
ANS( $answer2->cmp() );
</pre>
<td style="background-color:#eeccff;padding:7px;">
<p>
<b>Answer Evaluation:</b>
</p>
</p>
</td>
</td>
Line 128: Line 102:
<td style="background-color:#ddddff;border:black 1px dashed;">
<td style="background-color:#ddddff;border:black 1px dashed;">
<pre>
<pre>
Context()->texStrings;
BEGIN_PGML_SOLUTION
BEGIN_SOLUTION
 
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
Solution explanation goes here.
END_SOLUTION
END_PGML_SOLUTION
Context()->normalStrings;
 
COMMENT('MathObject version.');
 
ENDDOCUMENT();
ENDDOCUMENT();
</pre>
</pre>

Revision as of 15:51, 10 March 2023

Answer is a Number or a Formula - Try it out

Click to enlarge

This PG code shows how to write a question whose answer is a number or a formula.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros('PGstandard.pl','MathObjects.pl','PGML.pl');

TEXT(beginproblem());

Initialization:

Context('Numeric');

$a = non_zero_random(-9,9,1);
do { $b = random(2,9,1); } until ( $b != $a );

$answer1 = Compute("$a");
$answer2 = Compute("$a x^($b) + $b")->reduce();

Setup: We use do { $b = random(2,9,1); } until ( $b != $a ); to generate distinct random numbers.

BEGIN_PGML
Enter [`[$answer1]`]: [____]{$answer1} [@ helpLink('number') @]*

Enter [`[$answer2]`]: [____]{$answer2} [@ helpLink('formula') @]*
END_PGML

Main Text:

  • The helpLink command show some additional help for entering values.

BEGIN_PGML_SOLUTION

Solution explanation goes here.
END_PGML_SOLUTION
ENDDOCUMENT();

Solution:

Templates by Subject Area