MultipleChoiceProblems
This problem has been replaced with three alternatives:
Multiple Choice Problems: PG Code Snippet
This code snippet shows the essential PG code to include a multiple-choice question in a problem.
For an example of a multiple choice problem in which the choices are graphs, see Example 1 of GraphsInTables
We give two examples here. The first uses old-style answer checkers; the second newer parser based code. Note that the functionality that is provided in either case is different; the latter is syntactically cleaner and simpler, but doesn't have the same range of functions provided by the first. See also the Pop Up Lists page.
With Old-Style Answer Checkers
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "PGchoicemacros.pl", ); |
Initialization: Include |
$mc = new_multiple_choice(); $mc->qa( "What is your favorite color?", "blue" ); $mc->extra( "red", "green", ); $mc->makeLast("none of the above"); |
Setup: Create a new multiple choice object with
To make answers appear in a certain order (e.g., Yes followed by No and Maybe), use @quest = ("How many legs do cats have?", "How many legs to ostriches have?"); @ans = ("4","2"); $pick = random(0,1,1); $mc->new_checkbox_multiple_choice(); $mc->qa($quest[$pick],$ans[$pick]); $mc->makeLast("2","4","None of the above"); |
BEGIN_TEXT \{ $mc->print_q() \} $BR \{ $mc->print_a() \} END_TEXT |
Main text: In the text section we print the question and answers. |
$showPartialCorrectAnswers = 0; ANS( radio_cmp( $mc->correct_ans() ) ); ENDDOCUMENT(); |
Answer Evaluation: In most cases we will want to set |
With Newer Answer Checkers
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "parserRadioButtons.pl", ); |
Initialization: Include |
$mc = RadioButtons( [ "\( \sin(x) \)", "\( \tan(x) \)", "\( e^x \)", "None of these" ], "\( e^x \)", last => ["None of these"], labels => ["Sine", "Tangent", "Exponential", "None of these"] ); |
Setup: We create a radio button object with
To create a drop-down ("pop-up") option (having loaded $mc = PopUp( [ "?", "Blue", "Red", "Green", "None of the above" ], "Blue" ); Note that in this case we should specify a generic non-answer as the first option, so that when the selector is displayed it does not automatically give the student an answer (which may or may not be correct). |
BEGIN_TEXT Which function has a horizontal asymptote? $BR \{ $mc->buttons() \} END_TEXT |
Main text: In the text section we print the question and radio buttons giving the answers. For a PopUp object, the call to create the menu of options is |
$showPartialCorrectAnswers = 0; ANS( $mc->cmp() ); ENDDOCUMENT(); |
Answer Evaluation: In most cases we will want to set |