ListAnswers: Difference between revisions
No edit summary |
(added historical tag and gave updated problem link) |
||
(24 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<h2>Lists of Answers | {{historical}} | ||
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/SimpleFactoring.pg a newer version of this problem]</p> | |||
<h2>Lists of Answers</h2> | |||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> | <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> | ||
<em>This | <em>This is the PG code to check lists of objects entered into one answer blank as answers to a problem. | ||
<br /> | |||
<br /> | |||
For lists of answers entered into multiple answer blanks, please see [http://webwork.maa.org/wiki/MultiAnswerProblems MultiAnswerProblems]</em> | |||
</p> | </p> | ||
<p style="text-align:center;"> | <p style="text-align:center;"> | ||
Line 13: | Line 20: | ||
<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> | ||
Context("Numeric"); | |||
$factors = List(Compute("x+2"),Compute("x+3")); | |||
$roots = List( -3, -2 ); | |||
# If there were only one solution | |||
# $roots = List(4); | |||
# If there were no solutions | |||
# $roots = List("NONE"); | |||
</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> | ||
<p> | <p> | ||
Note that the argument of the <code>List</code> 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). | Note that the argument of the <code>List</code> 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). | ||
</p> | |||
<p> | |||
If, for example, there were no real roots, we should set <code>$roots = List("NONE");</code> so that students who enter a list of roots will not receive an error message about entering the wrong type of answer. If we were to use <code>$roots = String("NONE");</code> instead, students who enter anything other than a string (e.g., a list of numbers) will receive an error message. | |||
</p> | |||
<p> | |||
Similarly, if there were only one root at x=4, we would use <code>$roots = List(4);</code> instead of <code>$roots = Real(4);</code> to avoid sending error messages to students who enter multiple answers or NONE. | |||
</p> | </p> | ||
</td> | </td> | ||
Line 32: | Line 74: | ||
<td style="background-color:#ffdddd;border:black 1px dashed;"> | <td style="background-color:#ffdddd;border:black 1px dashed;"> | ||
<pre> | <pre> | ||
Context()->texStrings; | |||
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 | |||
Context()->normalStrings; | |||
</pre> | </pre> | ||
<td style="background-color:#ffcccc;padding:7px;"> | <td style="background-color:#ffcccc;padding:7px;"> | ||
<p> | <p> | ||
<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 103: | ||
<td style="background-color:#eeddff;border:black 1px dashed;"> | <td style="background-color:#eeddff;border:black 1px dashed;"> | ||
<pre> | <pre> | ||
ANS( $factors->cmp() ); | |||
ANS( $roots->cmp(ordered=>1) ); | |||
ENDDOCUMENT(); | |||
</pre> | </pre> | ||
<td style="background-color:#eeccff;padding:7px;"> | <td style="background-color:#eeccff;padding:7px;"> | ||
<p> | <p> | ||
<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=>1</code> flag in the <code>cmp()</code> call. The default is <code>ordered=>0</code> for unordered answers. | |||
</p> | |||
<p> | |||
Other commonly used options include <code>showHints=>1, showLengthHints=>1, partialCredit=>1</code> as arguments to the <code>cmp()</code> call. | |||
For all options, see the entries for "MathObjects-based Answer Checkers" and "Flags for Union()->cmp and List()->cmp" on [http://webwork.maa.org/pod/pg/doc/MathObjects/MathObjectsAnswerCheckers.html MathObjectsAnswerCheckers.html] | |||
</p> | </p> | ||
</td> | </td> | ||
Line 73: | Line 125: | ||
[[Category:Problem Techniques]] | [[Category:Problem Techniques]] | ||
<ul> | |||
<li>POD documentation: [http://webwork.maa.org/pod/pg/doc/MathObjects/MathObjectsAnswerCheckers.html MathObjectsAnswerCheckers.html]</li> | |||
</ul> |
Latest revision as of 13:12, 16 July 2023
This problem has been replaced with a newer version of this problem
Lists of Answers
This is the PG code to check lists of objects entered into one answer blank as answers to a problem.
For lists of answers entered into multiple answer blanks, please see MultiAnswerProblems
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl" ); TEXT(beginproblem()); |
Initialization:
Load the macro file |
Context("Numeric"); $factors = List(Compute("x+2"),Compute("x+3")); $roots = List( -3, -2 ); # If there were only one solution # $roots = List(4); # If there were no solutions # $roots = List("NONE"); |
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
If, for example, there were no real roots, we should set
Similarly, if there were only one root at x=4, we would use |
Context()->texStrings; 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 Context()->normalStrings; |
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) ); ENDDOCUMENT(); |
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
Other commonly used options include |
- POD documentation: MathObjectsAnswerCheckers.html