Multiple Choice with Radio Buttons

Multiple choice template

Complete Code

Download file: MultipleChoiceRadio.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

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

Preamble

The macro parserRadioButtons.pl must be loaded.

$radio1 = RadioButtons(
    [ [ 'Red', 'Blue', 'Green' ], 'None of these' ],
    'Blue',    # correct answer
);

$radio2 = RadioButtons(
    [ [ 'Red', 'Blue', 'Green' ], 'None of these' ],
    2,         # correct answer as an index (starting at 0)
    separator => $SPACE x 4
);

Setup

To create a radio object, use $radio = RadioButtons([choices,...],correct,options); For all options, see MultipleChoiceProblems and parserRadioButtons.pl. The context is not really necessary, but multiple choice questions are often follow-up questions, so we leave it in.

BEGIN_PGML
My favorite color is

[_]{$radio1}

The same question with horizontal options:

My favorite color is [_]{$radio2}
END_PGML

Statement

This is the problem statement in PGML.
BEGIN_PGML_SOLUTION
The correct answer to the first is [$radio1->correct_ans].

The correct answer to the first is [$radio2->correct_ans].
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

The correct_ans method can be called to get the correct answer.