Difference between revisions of "ListAnswers"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 13: Line 13:
 
<th> Explanation </th>
 
<th> Explanation </th>
 
</tr>
 
</tr>
  +
  +
<tr valign="top">
  +
<td style="background-color:#ddffdd;border:black 1px dashed;">
  +
<pre>
  +
DOCUMENT();
  +
loadMacros(
  +
"PGstandard.pl",
  +
"MathObjects.pl"
  +
);
  +
TEXT(beginproblem());
  +
</pre>
  +
</td>
  +
<td style="background-color:#ccffcc;padding:7px;">
  +
<p>
  +
<b>Initialization:</b>
  +
Load the macro file <code>MathObjects.pl</code>.
  +
</p>
  +
</td>
  +
</tr>
  +
 
<tr valign="top">
 
<tr valign="top">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
$factors = List(Compute("x+2"),Compute("x+3"));
+
$factors = List(Compute("x+2"),Compute("x+3"));
$roots = List( -3, -2 );
+
$roots = List( -3, -2 );
 
</pre>
 
</pre>
 
</td>
 
</td>
 
<td style="background-color:#ffffcc;padding:7px;">
 
<td style="background-color:#ffffcc;padding:7px;">
 
<p>
 
<p>
  +
<b>Setup:</b>
 
We need make no changes or additions to the tagging and description section of the PG file, or to the problem initialization section (unless we need to load some macros for the type of problem that we're creating). In the problem set-up section of the file, we include the definition of the list(s) that we're expecting as an answer.
 
We need make no changes or additions to the tagging and description section of the PG file, or to the problem initialization section (unless we need to load some macros for the type of problem that we're creating). In the problem set-up section of the file, we include the definition of the list(s) that we're expecting as an answer.
 
</p>
 
</p>
Line 32: Line 53:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
BEGIN_TEXT
+
BEGIN_TEXT
What are the factors of \(x^2 + 5 x + 6\)?
+
What are the factors of \(x^2 + 5 x + 6\)?
$BR
+
$BR
Factors = \{ ans_rule(25) \}
+
Factors = \{ ans_rule(25) \}
$BR
+
$BR
${BITALIC}(Enter the factors as a comma-separated
+
${BITALIC}(Enter the factors as a comma-separated
list.)$EITALIC
+
list.)$EITALIC
$PAR
+
$PAR
What are the roots of this equation?
+
What are the roots of this equation?
$BR
+
$BR
Roots = \{ ans_rule(15) \}
+
Roots = \{ ans_rule(15) \}
$BR
+
$BR
${BITALIC}(Enter the roots in a comma-separated
+
${BITALIC}(Enter the roots in a comma-separated
list, ${BBOLD}ordered from smallest to
+
list, ${BBOLD}ordered from smallest to
largest$EBOLD.)$EITALIC
+
largest$EBOLD.)$EITALIC
END_TEXT
+
END_TEXT
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
In the text section of the problem, we ask for the answers as we'd expect. It's generally a good idea to make sure that it's clear what we expect students to enter (in this case, a comma-separated list). To point out the obvious, there's no reason in this case to make only one of the requested lists have a specific order... except that it lets us see how to do it in this example problem.
 
  +
<b>Main text:</b>
  +
We ask for the answers as we'd expect. It's generally a good idea to make sure that it's clear what we expect students to enter (in this case, a comma-separated list). To point out the obvious, there's no reason in this case to make only one of the requested lists have a specific order... except that it lets us see how to do it in this example problem.
 
</p>
 
</p>
 
</td>
 
</td>
Line 58: Line 80:
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
<pre>
ANS( $factors-&gt;cmp() );
+
ANS( $factors-&gt;cmp() );
ANS( $roots-&gt;cmp( ordered=&gt;1 );
+
ANS( $roots-&gt;cmp( ordered=&gt;1 );
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<p>
Then, in the answer and solution section of the problem we can just check the answers against the correct List answers. To force the students' list answers to match the order of the correct answer, we include the <code>ordered=&gt;1</code> flag in the <code>cmp()</code> call.
 
  +
<b>Answer Evaluation:</b>
  +
We can just check the answers against the correct List answers. To force the students' list answers to match the order of the correct answer, we include the <code>ordered=&gt;1</code> flag in the <code>cmp()</code> call. For more options, see [http://webwork.maa.org/doc/cvs/pg_CURRENT/doc/MathObjects/MathObjectsAnswerCheckers.html MathObjectsAnswerCheckers.html]
 
</p>
 
</p>
 
</td>
 
</td>
Line 73: Line 96:
   
 
[[Category:Problem Techniques]]
 
[[Category:Problem Techniques]]
  +
  +
  +
  +
<ul>
  +
<li>POD documentation: [http://webwork.maa.org/doc/cvs/pg_CURRENT/doc/MathObjects/MathObjectsAnswerCheckers.html MathObjectsAnswerCheckers.html]</li>
  +
</ul>

Revision as of 14:54, 6 February 2010

Lists of Answers: PG Code Snippet

This code snippet shows the essential PG code to check lists of objects as answers to a problem. Note that these are insertions, 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"
);
TEXT(beginproblem());

Initialization: Load the macro file MathObjects.pl.

$factors = List(Compute("x+2"),Compute("x+3"));
$roots = List( -3, -2 );

Setup: We need make no changes or additions to the tagging and description section of the PG file, or to the problem initialization section (unless we need to load some macros for the type of problem that we're creating). In the problem set-up section of the file, we include the definition of the list(s) that we're expecting as an answer.

Note that the argument of the List call are the objects in the list, which can be any MathObjects. Here we create a list of Formulas and a list of Reals (the numbers that we use in the second list will be promoted to Real MathObjects when the List is created).

BEGIN_TEXT
What are the factors of \(x^2 + 5 x + 6\)?
$BR
Factors = \{ ans_rule(25) \}
$BR
${BITALIC}(Enter the factors as a comma-separated
list.)$EITALIC
$PAR
What are the roots of this equation?
$BR
Roots = \{ ans_rule(15) \}
$BR
${BITALIC}(Enter the roots in a comma-separated
list, ${BBOLD}ordered from smallest to 
largest$EBOLD.)$EITALIC
END_TEXT

Main text: We ask for the answers as we'd expect. It's generally a good idea to make sure that it's clear what we expect students to enter (in this case, a comma-separated list). To point out the obvious, there's no reason in this case to make only one of the requested lists have a specific order... except that it lets us see how to do it in this example problem.

ANS( $factors->cmp() );
ANS( $roots->cmp( ordered=>1 );

Answer Evaluation: We can just check the answers against the correct List answers. To force the students' list answers to match the order of the correct answer, we include the ordered=>1 flag in the cmp() call. For more options, see MathObjectsAnswerCheckers.html

Problem Techniques Index