WeBWorK Problems

answerhints for multiple choice questions

answerhints for multiple choice questions

by Greg Schlitt -
Number of replies: 1

I'd like to provide some feedback to students when certain wrong answers are selected in multiple choice questions. As an example, for a question asking for the first nonzero even number, provide a comment if "4" is selected. The code below is modeled on the "answerhints.pl" model (in a very amateurish way) and does not work. Help?

DOCUMENT(); 

loadMacros(

  "PGstandard.pl",

  "MathObjects.pl",

  "answerHints.pl",

  "PGchoicemacros.pl"

  );

 #Multiple Choice

$radio = new_multiple_choice();

$radio->qa("What is the least nonzero even number","two");

$radio->extra("one","three","four");

$radio->makeLast("infinity"); 

 TEXT(beginproblem());

BEGIN_TEXT

 \{ $radio->print_q() \}

\{ $radio->print_a() \}

END_TEXT

 ANS(radio_cmp($radio->correct_ans())->withPostFilter(AnswerHints("four"=>"Note you want the *least* nonzero even number")));

#ANS(radio_cmp($radio->correct_ans()) ); 

ENDDOCUMENT();

Tags:
In reply to Greg Schlitt

Re: answerhints for multiple choice questions

by Davide Cervone -

The AnswerHints() macro relies on the correct answer being a MathObject, so it doesn't work with radio_cmp() function, which isn't MathObejct-based. You might consider using the parserRadioButtons.pl macro file and the RadioButtons() macro that it defines. See the documentation at the top of the macro file for details.