Difference between revisions of "MultipleSelectProblems"

From WeBWorK_wiki
Jump to navigation Jump to search
m
m
Line 72: Line 72:
 
</p>
 
</p>
 
<p>
 
<p>
To force an answer (either a new extra answer, or the correct answer) to appear last in the list of options, use the <code>makeLast</code> method. All answers not in <code>makeLast()</code> will be scrambled when the multiple choice problem is shown to students. If the only correct answer is "None of the above" (or "All of the above"), use
+
To ensure an answer appears last in the list of options (either a new extra answer or the correct answer), use the <code>makeLast</code> method. All answers not in <code>makeLast()</code> will be shuffled when the multiple choice problem is shown to students, and answers in <code>makeLast</code> will retain their original ordering. For example, if the only correct answer is "None of the above" (or "All of the above"), use
 
<pre>
 
<pre>
 
$cmc->qa("question","None of the above");</code>
 
$cmc->qa("question","None of the above");</code>
Line 80: Line 80:
 
</p>
 
</p>
 
<p>
 
<p>
To force answers to appear in a certain order (like Yes followed by No), use only <code>$cmc->qa("question","Yes"); $cmc->makeLast("Yes","No");</code> and do not use <code>extra( )</code> at all. In this case, to randomize the question and answer, use
+
To force answers to appear in a certain order (like Yes followed by No), use <code>$cmc->qa("question","Yes"); $cmc->makeLast("Yes","No");</code> and do not use <code>extra( )</code> at all. In this case, to randomize the question and answer, where the answer to question 1 is Yes and the answer to question 2 is No, use
 
<pre>
 
<pre>
 
@quest = ("question 1","question 2");
 
@quest = ("question 1","question 2");

Revision as of 17:16, 1 January 2010

Multiple Select Problems (or Checkbox Multiple Choice or Select All That Apply)

This code snippet shows the essential PG code to include multiple select question (or checkbox multiple choice or select all that apply) in a problem. A multiple choice question has only one correct answer, whereas a checkbox multiple choice question may require several items to be selected at the same time to be correct.

Note that in this example we use old-style checkbox multiple choice answer objects. The new-style MathObjects do not yet have a checkbox multiple choice answer object yet.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();  

loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

Initialization: We must load PGchoicemacros.pl and PGanswermacros.pl.

$cmc = new_checkbox_multiple_choice();
$cmc -> 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} \)",
"\( e^{x^2} e^{x^{-1}} \)",                
"\( e^{ (x^3+1) / x } \)",
);
$cmc -> extra(
"\( \displaystyle \frac{ e^{x^2} }{ e^x } \)$BR",
"\( e^{x^2} + e^{1/x} \)",
);
# The next line can be uncommented.
# $cmc->makeLast("All of the above");

Setup: Create a new checkbox multiple choice object named $cmc with $cmc->new_checkbox_multiple_choice();.

Use $cmc->qa("question","correct answer 1","correct answer 2"); to store the question string and correct answer strings. Note that unlike match lists and select lists, you cannot call qa( ) again. If you include math symbols you should switch to LaTeX mode using \( \), and, if necessary, using \displaystyle and extra spacing $BR after each entry. For example, $cmc->qa("question","\( x^2 \)$BR","\( \displaystyle \frac{x^2}{4-x} \)$BR"); Note that we used a period to join parts of the question string: "text " . "more text"

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

To ensure an answer appears last in the list of options (either a new extra answer or the correct answer), use the makeLast method. All answers not in makeLast() will be shuffled when the multiple choice problem is shown to students, and answers in makeLast will retain their original ordering. For example, if the only correct answer is "None of the above" (or "All of the above"), use

$cmc->qa("question","None of the above");</code>
$cmc->extra("very wrong 1","distractor 2","red herring 3");
$cmc->makeLast("None of the above");

To force answers to appear in a certain order (like Yes followed by No), use $cmc->qa("question","Yes"); $cmc->makeLast("Yes","No"); and do not use extra( ) at all. In this case, to randomize the question and answer, where the answer to question 1 is Yes and the answer to question 2 is No, use

@quest = ("question 1","question 2"); 
@ans = ("Yes","No"); 
$pick = random(0,1,1);
$cmc->new_checkbox_multiple_choice();
$cmc->qa($quest[$pick],$ans[$pick]);
$cmc->makeLast("Yes","No");

BEGIN_TEXT

This is a place to insert additional text if you wish.
$PAR
\{ $cmc -> print_q() \}
$PAR
\{ $cmc -> print_a() \}
END_TEXT

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

install_problem_grader(~~&std_problem_grader);

$showPartialCorrectAnswers = 0;

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

ENDDOCUMENT();

Answer Evaluation: We use the standard problem grader, an all-or-nothing grader that gives no partial credit, and set $showPartialCorrectAnswers = 0; to withhold credit and hide the correct answers until the student answers everything correctly. Otherwise, the student can use a guess-and-check method to find the correct answers by the partial credit and feedback received. Use the checkbox_cmp answer checker.

Problem Techniques Index