## WeBWorK Problems

### Scoring a Multiple Choice Problem

by Louis Zulli -
Number of replies: 5
A colleague would like WW to score his multiple choice problems in the following manner: Correct answer = 5pts, Incorrect answer = 0pts, No Answer=1pt.

How can a problem be written to achieve this effect?

Thanks.

### Re: Scoring a Multiple Choice Problem

by Davide Cervone -
There are several approaches to this. One would be to write a custom grader, but it can also be done with a custom answer evaluator. I assume you are planning to use radio buttons? It's been a while since I looked at them, but it should be possible to use a Parser-based string answer checker that allows blank answers and that uses a custom checker routine that returns a score of 1, .2 or 0, depending on the answer. The professor would need to assign the problem a value of 5 points. It is pretty easy to provide a custom checker for the Parser checkers, either with the "checker=>" option to the string's cmp routine, or with the custom_cmp() function from the answerCustom.pl file in /pg/macros.

I usually write the example for you, but haven't had the chance. If I can, I'll do it this weekend, but that's only if I get my grading done. (Or can't take it any more.)

Davide

### Re: Scoring a Multiple Choice Problem

by Louis Zulli -
Thanks Davide.

Your reply reminded me of another issue. We created a draft of a multiple choice quiz that uses radio buttons. Each problem uses new_multiple_choice().

However, we appear to have a difficulty. Once a radio button is selected, there seems to be no way to deselect it. Another button can be selected to replace it, but it seems impossible to leave all buttons deselected once one is selected.

I suppose we can resolve this issue and the one in the original post by adding a button for "I choose not to respond." Or we could abandon radio buttons and just use answer boxes. But are there better solutions?

Louis

### Re: Scoring a Multiple Choice Problem

by Davide Cervone -
That is how the browsers have implemented radio buttons.

It would be possible to use JavaScript to make it possible to deselect the radio buttons. For example, there could be a "No Answer" button that would uncheck all the radio buttons. It might even be possible to arrange for CTRL-click to uncheck a button. But these would require that the student have JavaScript enabled in his or her browser.

I'm not sure if you are allowing multiple submissions of the problem, or how you are planning to deal with the answer results at the top of the page, but if the student can do multiple submissions, it would be possible to do the "No Answer" button without JavaScript. But you are getting pretty close to just having a "I choose not to respond" choice in the radio buttons.

(BTW, if I remember correctly, it is possible to prevent the answer results section from showing up at all if you don't want to be telling them about correct answers.)

Davide

### Re: Scoring a Multiple Choice Problem

by Davide Cervone -
Louis:

I have added the ability to uncheck the radio buttons, either by clicking them a second time, or shift-clicking them (the problem author specifies which). You need to set an additional option for the RadioButtons() function: either uncheckable=>1 or uncheckable=>"shift".

Note that this requires the user to have JavaScript active. It is possible for students to have JavaScript turned off, and so unchecking would not be possible in that case. Currently no message is issued, but it would be possible to have a message added to the problem to warn the user that they would be able to uncheck the buttons if they turned on JavaScript.

Davide

### Re: Scoring a Multiple Choice Problem

by Davide Cervone -
OK, I've just committed a new file (parserRadioButtons.pl) to the CVS repository for pg/macros. This implements a Parser-based method for handling radio buttons. There is some documentation at the top of the file, but here is a simple example:
    DOCUMENT();

"PG.pl",
"PGbasicmacros.pl",
"Parser.pl",
);

TEXT(beginproblem);

$radio = RadioButtons(["Choice 1", "Choice 2"],1); BEGIN_TEXT Choose one:$BR
\{$radio->buttons\} END_TEXT ANS($radio->cmp);
$showPartialCorrectAnswers = 1; ENDDOCUMENT();  This sets up a "RadioButtons" object by giving the choices and the index of the correct answer. There are a number of additional options that can be supplied (see the parserRadioButtons.pl file for details), which control things like what to use as the answers when the students select the various buttons (these can be numbers, letters, or the button strings themselves, or any other strings you set), and what to use between the entries (spaces,$BR, $PAR, etc). To handle your special point arrangement, you can supply a custom answer checker that returns partial credit according to your model above. It turns out that the standard Parser objects don't provide a method for returning partial credit (I'll have to fix that), but we can use the List checker, which does. Here is an example:  DOCUMENT(); loadMacros( "PG.pl", "PGbasicmacros.pl", "PGanswermacros.pl", "Parser.pl", "parserRadioButtons.pl", ); TEXT(beginproblem);$radio = RadioButtons(["Choice 1", "Choice 2"],1);

BEGIN_TEXT
Choose one:$BR \{$radio->buttons\}
END_TEXT

Context($radio->{context});$cmp = List($radio)->cmp(list_checker=> sub { my ($correct,$student,$ans) = @_;
return .2 if $student->[0] eq ""; return ($student->[0] eq $correct->[0] ? 1 : 0); } );$cmp->install_pre_filter('erase');  # allow blank answers

ANS($cmp);$showPartialCorrectAnswers = 1;

ENDDOCUMENT();


Here we have to work a little bit to make everything work out. First, we must set the context to the one from the $radio object, so that the list will have access to the string that were set up for the$radio. Then we make a new answer checker based on the list checker with a custom list checker. The custom checker returns .2 if the student didn't answer anything, and returns 1 if correct, or 0 if not. Finally, we need to allow blank answers, so we remove the prefilter that WeBWorK installs to avoid checking blanks.

You will need to assign the problem a score of 5 (in the homework set editor) in order to make the totals come out the way you want.

Hope that does what you need.

Davide