Multiple Choice with Checkbox

Multiple choice template

Complete Code

Download file: MultipleChoiceCheckbox.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'parserCheckboxList.pl', 'PGcourse.pl');

Preamble

The parserCheckboxList.pl is used for check box answers.

$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

First, call CheckboxList to create a check box list answer object. The format is

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 array reference, then the order of the choices will be randomized.

Setting the option separator 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 hard copy.

See parserCheckboxList.pl 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.