WeBWorK Problems

how to check two different answers

Re: how to check two different answers

by Gavin LaRose -
Number of replies: 0
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