WeBWorK Problems

how to check two different answers

how to check two different answers

by Siman Wong -
Number of replies: 1
I'd like to ask students to enter two different answers for the same equation. For each answer I can check its correctness, but how can I be sure that the two answers are different? In case that matters: I need to do this for two problems; in one case each answer is a single number, in another case each answer is a pair of numbers. THANKS!
In reply to Siman Wong

Re: how to check two different answers

by Gavin LaRose -
Hi Siman,

To grade two different answers for the same equation in the same problem you may want to use parserMultiAnswer: see http://webwork.maa.org/wiki/MultiAnswerProblems . Something like the following would probably work in this case, given the two answers defined in the variables $ans1 and $ans2.

loadMacros( "parserMultiAnswer.pl" );
...
$check = MultiAnswer( $ans1, $ans2 )->with(
    singleResult => 1,
    checker => sub {
        my ( $correct, $student, $ansHash ) = @_;
        my ( $cor1, $cor2 ) = @$correct;
        my ( $stu1, $stu2 ) = @$student;
        return ( ( $cor1 == $stu1 &&
                   $cor2 == $stu2 ) ||
                 ( $cor1 == $stu2 &&
                   $cor2 == $stu1 ) );
} );

If you have the answers being checked in subsequent problems this becomes harder, because it's difficult to find out what the student entered in one problem from within another problem.

Gavin