WeBWorK Main Forum

multi answer

multi answer

by Zak Zarychta -
Number of replies: 5
 I'm trying to write a question that takes one answer from a student, compares it with two correct possibilities and then grades the students answer correct if it matches either correct answer. 
I have an idea that i should be using multianswer but am struggling. I've used the checker and adapted is as follows

$multians = MultiAnswer($ans1, $ans2)->with(
  singleResult => 1,
  checker => sub {
      my ( $correct, $student, $self ) = @_;
      my ( $f1stu ) = @{$student};
      my ( $f1, $f2 ) = @{$correct};
      if ( ($f1 == $f1stu || $f2 == $f1stu) ) {
          return [1];
          } else {
              return [0];

Any insight is gratefully recieved
In reply to Zak Zarychta

Re: multi answer

by Gavin LaRose -
Hi Zak,

I think you may be having trouble with a mismatch between the number of answers that the MultiAnswer object expects to be provided. The function call

  $multians = MultiAnswer($ans1, $ans2)->with(

is going to create an answer object that expects two answers from the student. For a single answer it probably makes better sense to use a custom checker instead, something like the following

  $ans1 = Compute(...);
  $ans2 = Compute(...);
  Enter your answer \{ ans_rule(25) \}
  ANS( $ans1->cmp( checker => sub {
      my ( $correct, $student, $ansHash ) = @_;
      return $ans1 == $student || $ans2 == $student;
    } ) );

See <http://webwork.maa.org/wiki/CustomAnswerCheckers>.


In reply to Zak Zarychta

Re: multi answer

by Arnold Pizer -

How hard would it be to implement an OR operator in WeBWorK? A question mostly for Davide I assume.

For example maybe 

$root1 = Compute(1);
$root2 = Compute(2);
$root3 = Compute(3);

$orans = OrAnswer($root1, $root2, $root3);
ANS($orans->cmp() );

or maybe even

ANS(OR($root1, $root2, $root3)->cmp() );

If the student answer does not match any possibility, then use the first listed MathObject (or the last if people think that is more natural) for generating error messages, etc.


In reply to Arnold Pizer

Re: multi answer

by Michael Gage -
Here is my summary of prior work in this direction.  I'm fairly sure it is complete for the macros which are in the webwork/pg directory. I can't vouch for macros in the library.

One version of this is the pc_evaluator in PGasu.pl which John Jones wrote many years ago.  This takes a series of evaluators and applies them to the student answer until it succeeds and then provides appropriate partial credit.
(The partial credits could all be full credit. )

You could also use this a model for a more up-to-date version or OR applied to answer evaluators. 

Versions of OR and AND are also defined in AnswerHash.pm. These might need some modifications to play well with MathObjects since they take answer hashes as arguments not Answer Evaluators. These implimentations simply ignore the problem of handling error evaluations.
In reply to Arnold Pizer

Re: multi answer

by Davide Cervone -

I have made up a new OneOf() MathObject class that is a subclass of the List class so that you can give it a list of possible correct answers and it will look to see if the student answer is one of the given ones. The correct answer is formatted to list all the possibilities.

I've attached the file here, but will also add it to pg/macros and issue a pull request for that.

Hope that is satisfactory.

In reply to Davide Cervone

Re: multi answer

by Arnold Pizer -
Hi Davide,

Thanks.  This is excellent.  Having the correct answer display all the possible correct answers is clearly the best way to do things.