Difference between revisions of "ListAnswers"

From WeBWorK_wiki
Jump to navigation Jump to search
m
Line 87: Line 87:
 
<pre>
 
<pre>
 
ANS( $factors-&gt;cmp() );
 
ANS( $factors-&gt;cmp() );
ANS( $roots-&gt;cmp( ordered=&gt;1, );
+
ANS( $roots-&gt;cmp(ordered=&gt;1) );
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();

Revision as of 15:35, 6 February 2010

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

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).

If, for example, there were no real roots, we should set $roots = List("NONE"); (instead of $roots = String("NONE");) so that students who type in a list of roots will not receive an error message about entering the wrong type of answer. That is, when $roots = String("NONE");, the type of answer is set as string, so if a student enters a list of numbers an error will be generated.

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) );

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 ordered=>1 flag in the cmp() call. The default is ordered=>0 for unordered answers.

Other commonly used options include showHints=>1, showLengthHints=>1, partialCredit=>1 as arguments to the cmp() call. For all options, see the entries for List on MathObjectsAnswerCheckers.html

Problem Techniques Index