## WeBWorK Problems

### Multiple choice - one answer - several correct

by Murphy Waggoner -
Number of replies: 4
Howdy,

I want to write a set of questions on using theorems for integration in complex variables.  Because the answers are mostly 0 or 2pi i k for appropriate k, the students could guess the answers so I want to ask more.

The plan is to ask about the hypotheses of the theorems.  For instance, "is the contour closed or not?", "what are the singularities of the integrand?", etc.

I want to ask which theorem the student used, but since there is more than one way to skin that cat I want to allow for all that are correct.  For example, they might have parameterized and evaluated an integral in t or they might have used the Cauchy Integral Formula, and both ways would lead to the correct answer.

OTOH, they don't have to select both methods from the list - just one.  I really just want to check against the wrong answers.  For instance, to say one used the Cauchy Integral Formula when the contour is not a closed curve would be incorrect.

So, the ultimate question is whether there is a way to write a multiple choice question (i.e., drop down menu question) where the student could choose a or c from a, b, c, d, e and both would be counted as correct?  If not, is there a way to write a custom answer checker for multiple choice questions?

Thanks.

### Re: Multiple choice - one answer - several correct

by Alex Jordan -
This seems to work, if your goal is to have them choose one answer only. (If you would also like them to be able to select multiple correct answers, more must be done.) Use parserOneOf.pl to create a Math Object list of all correct answers, and pass its checker to ANS, not the popup's actual answer checker. So you are only using the menu functionality of the popup object, not its answer checker.

One thing I would take note of here is how the answer options have been coded in as perl variables, which are then referred to multiple times. If you actually repeat the strings themselves multiple times in the code, there is the opportunity for a typo or something to make them not match.

DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"parserPopUp.pl",
"parserOneOf.pl",
"PGML.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

######################################

$o​ne= "one";$two = "two";
$three = "three";$ans = $one;$popup = PopUp(["?", $one,$two, $three],$ans);
# It doesn't matter what we put as the "correct answer" here.

######################################

BEGIN_PGML

What number is less than three?

[@$popup->menu@]* END_PGML ###################################### Context()->strings->add("?"=>{},$o​ne=>{}, $two=>{},$three=>{});
ANS(OneOf($one,$two)->cmp());

ENDDOCUMENT();


### Re: Multiple choice - one answer - several correct

by Murphy Waggoner -
Thanks.  I didn't know about OneOf.  I like it.

I also didn't know enough about popups to realize I could check the answers with the standard answer checker.  Nice.

### Re: Multiple choice - one answer - several correct

by Davide Cervone -
Here is a modified version of Alex's answer that simplifies things slightly.
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserPopUp.pl",
"parserOneOf.pl",
"PGML.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

######################################

@choices = ("?","one", "two", "three");

$popup = PopUp([@choices],$choices[0]);  # It doesn't matter which is used as the "correct answer".
Context($popup->context); # use the pop-up's context (already has the choices as strings); ###################################### BEGIN_PGML What number is less than three? [@$popup->menu@]*
END_PGML

######################################

ANS(OneOf(@choices[1,2])->cmp());


Here, the choices are put into an array, and you can refer to them as $choices[1], $choices[2] and $choices[3], or as a collection, as @choices. So  PopUp([@choices],$choices[0]);

makes a popup with all the choices, using the first one (the question mark) as the correct answer, which (as Alex points out), is never used, since the pop-up's answer checker is not used.

You can refer to a subset of the answers (known as a "slice" of the array) via @slice[1,2] (note the use of @ rather than $ to refer to the variable, and the use of multiple indices within the square brackets). Thus  OneOf(@choices[1,2])  produces a MathObject that takes either of the first two choices ("one" or "two"). Using the array rather than individual variables makes it easier to add and remove entries in the pop-up. For example, if you had five entries in the array and the first 3 were correct, you could use  OneOf(@choices[1..3])  You can also mix .. with commas:  OneOf(@choices[1..3,5])  Note that the indices start at 0, which is why having "?" as the first entry in the array helps. It means that the indices for the "real" answers are 1, 2, 3, etc. The final simplification is to set the context to the pop-up's context rather than adding the strings to the current context. The strings have already been added to the context used by the pop-up internally. In reply to Alex Jordan ### Re: Multiple choice - one answer - several correct by Davide Cervone - PS, there is an update to parserPopUp.pl that allows it to be used in PGML more easily. With the new version, you can do BEGIN_PGML What number is less than three? [_______]{$popup}
END_PGML

as you would any other MathObject.