Multiple choice template
Download file: MultipleChoiceCheckbox.pg
DOCUMENT(); loadMacros('PGstandard.pl', 'PGML.pl', 'parserCheckboxList.pl', 'PGcourse.pl');
Preamble
Include parserCheckboxList.pl
in the loadMacros
.
$checks1 = CheckboxList( [ "\(e^{x^2} e^{1/x}\)", "\(e^{x^2} e^{x^{-1}}\)", "\(\displaystyle\frac{e^{x^2}}{e^x}\)", 'None of the above' ], [ 0, 1 ] ); $checks2 = CheckboxList( [ [ "\(e^{x^2} e^{1/x}\)", "\(e^{x^2} e^{x^{-1}}\)", "\(\displaystyle\frac{e^{x^2}}{e^x}\)" ], 'None of the above' ], [ 0, 1 ] ); # This makes the checkbox list horizontal. $checks3 = CheckboxList( [ "\(e^{x^2} e^{1/x}\)", "\(e^{x^2} e^{x^{-1}}\)", "\(\displaystyle\frac{e^{x^2}}{e^x}\)", 'None of the above' ], [ 0, 1 ], separator => $SPACE x 10 );
Setup
To setup, CheckboxList
creates a new object. The format is
$checks = CheckboxList([choices, ...], [correct_choices, ...], options);
where the correct_choices
can either match those in choices
or be the indices (starting at 0).
If we nest choices
in another arrayref, then the order of the choices will be randomized.
Using the option separator
and setting to $SPACE x 10
results in a horizontal checklist. Note that $SPACE
should be used and not
so that this works in both html and hardcopy.
See the POD for more options.
BEGIN_PGML Select all expressions that are equivalent to [`e^{x^2 + 1/x}`]. There may be more than one correct answer. [_]{$checks1} **Alternative with randomly ordered choices** [_]{$checks2} **Alternative shown with horizontal spacing** [_]{$checks3} END_PGML
Statement
This is the problem statement in PGML.BEGIN_PGML_SOLUTION The correct answer to the first is [$checks1->correct_ans]. The correct answer to the second is [$checks2->correct_ans]. The correct answer to the third is [$checks3->correct_ans]. END_PGML_SOLUTION ENDDOCUMENT();
Solution
The correct_ans
method can be called to get the correct answer.