From WeBWorK_wiki
Revision as of 21:53, 7 June 2015 by Paultpearson (talk | contribs) (Add link to PGML version in OPL)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Multiple Choice with Checkboxes

Click to enlarge

This PG code shows how to write a multiple choice question with possibly more than one correct answer by using checkboxes.

Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:





$mc = new_checkbox_multiple_choice();

$mc -> qa (
"Select all expressions that are equivalent to  
\( e^{x^2 + 1/x} \).  There may be more than
one correct answer.", 
"\( e^{x^2} e^{1/x} \) $BR",
"\( e^{x^2} e^{x^{-1}} \) $BR",                

$mc -> extra(
"\( \displaystyle \frac{ e^{x^2} }{ e^x } \) $BR",

$mc -> makeLast("None of the above");

Setup: Use the question and answer method qa( ) to store the question string and correct answer strings in $mc. For example, $mc->qa("question","correct answer 1","correct answer 2");. Note that unlike match lists and select lists, you cannot call the qa( ) method again. If you include math symbols you should switch to LaTeX mode \( \), and use \displaystyle with extra spacing $BR after each entry, if necessary. For example,

"Question text here.", 
"\( x^2 \) $BR", 
"\( \displaystyle \frac{x^2}{4-x} \) $BR" 

Incorrect answers are specified as a list of string arguments to the extra( ) method.

The arguments of the makeLast( ) method will appear at the end of the list and will not be shuffled, unlike the arguments of extra( ), which are shuffled. The arguments to makeLast( ) can either be a new extra answers or only the correct answer. For example, if the only correct answer is "None of the above", use

$mc->qa("question","None of the above");
$mc->extra("very wrong","distractor","red herring");
$mc->makeLast("None of the above");

To make answers appear in a certain order (e.g., Yes followed by No and Maybe), use $mc->qa("question","Yes"); $mc->makeLast("Yes","No","Maybe"); and do not use extra( ) at all.

Additional instructions can be put here.
\{ $mc -> print_q() \}
\{ $mc -> print_a() \}

Main Text: Print the question and answers. Print the question text using $mc->print_q() and the list of all answers using $mc->print_a().


$showPartialCorrectAnswers = 0;

ANS( checkbox_cmp( $mc->correct_ans() ) );

Answer Evaluation:

The correct answer is \{ $mc->correct_ans() \}

COMMENT('MathObject version.');



Templates by Subject Area