Difference between revisions of "MultipleSelectProblems"

From WeBWorK_wiki
Jump to navigation Jump to search
m
(link to forum thread with method to give partial credit)
(14 intermediate revisions by 3 users not shown)
Line 6: Line 6:
   
 
<p>
 
<p>
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.
+
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.
 
</p>
 
</p>
   
Line 24: Line 24:
   
 
loadMacros(
 
loadMacros(
"PG.pl",
+
"PGstandard.pl",
"PGbasicmacros.pl",
 
 
"PGchoicemacros.pl",
 
"PGchoicemacros.pl",
"PGanswermacros.pl",
 
 
"PGcourse.pl",
 
"PGcourse.pl",
 
);
 
);
Line 42: Line 41:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
$cmc = new_checkbox_multiple_choice();
+
$mc = new_checkbox_multiple_choice();
$cmc -> qa (
+
$mc -> qa (
 
"Select all expressions that are equivalent to
 
"Select all expressions that are equivalent to
 
\( e^{x^2 + 1/x} \). There may be more than
 
\( e^{x^2 + 1/x} \). There may be more than
 
one correct answer.",
 
one correct answer.",
"\( e^{x^2} e^{1/x} \)",
+
"\( e^{x^2} e^{1/x} \)$BR",
"\( e^{x^2} e^{x^{-1}} \)",
+
"\( e^{x^2} e^{x^{-1}} \)$BR",
"\( e^{ (x^3+1) / x } \)",
+
"\( e^{ (x^3+1) / x } \)$BR",
 
);
 
);
$cmc -> extra(
+
$mc -> extra(
 
"\( \displaystyle \frac{ e^{x^2} }{ e^x } \)$BR",
 
"\( \displaystyle \frac{ e^{x^2} }{ e^x } \)$BR",
"\( e^{x^2} + e^{1/x} \)",
+
"\( e^{x^2} + e^{1/x} \)$BR",
 
);
 
);
# The next line can be uncommented.
 
  +
$mc -> makeLast("None of the above");
# $cmc->makeLast("All of the above");
 
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 62: Line 60:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
Create a new checkbox multiple choice object named <code>$cmc</code> with <code>$cmc->new_checkbox_multiple_choice();</code>.
+
Create a new checkbox multiple choice object named <code>$mc</code> with <code>$mc->new_checkbox_multiple_choice();</code>.
 
</p>
 
</p>
 
<p>
 
<p>
Use <code>$cmc->qa("question","correct answer 1","correct answer 2");</code> to store the question string and correct answer strings. Note that unlike match lists and select lists, you cannot call <code>qa( )</code> again. If you include math symbols you should switch to LaTeX mode using <code>\( \)</code>, and, if necessary, using <code>\displaystyle</code> and extra spacing <code>$BR</code> after each entry. For example, <code>$cmc->qa("question","\( x^2 \)$BR","\( \displaystyle \frac{x^2}{4-x} \)$BR");</code>
+
Use the question and answer method <code>qa( )</code> to store the question string and correct answer strings in <code>$mc</code>. For example, <code>$mc->qa("question","correct answer 1","correct answer 2");</code>. Note that unlike match lists and select lists, you cannot call the <code>qa( )</code> method again. If you include math symbols you should switch to LaTeX mode
  +
<code CLASS="tex2math_ignore">\( \)</code>, and use <code>\displaystyle</code> with extra spacing <code>$BR</code> after each entry, if necessary. For example, <code CLASS="tex2math_ignore">$mc->qa("question", "\( x^2 \) $BR", "\( \displaystyle \frac{x^2}{4-x} \) $BR" );</code>
 
</p>
 
</p>
 
<p>
 
<p>
Incorrect answers are specified as a list of arguments to the <code>extra</code> method.
+
Incorrect answers are specified as a list of string arguments to the <code>extra( )</code> method.
 
</p>
 
</p>
 
<p>
 
<p>
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
+
The arguments of the <code>makeLast( )</code> method will appear at the end of the list and will not be shuffled, unlike the arguments of <code>extra( )</code>, which are shuffled. The arguments to <code>makeLast( )</code> 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
 
<pre>
 
<pre>
$cmc->qa("question","None of the above");</code>
+
$mc->qa("question","None of the above");
$cmc->extra("very wrong","distractor","red herring");
+
$mc->extra("very wrong","distractor","red herring");
$cmc->makeLast("None of the above");
+
$mc->makeLast("None of the above");
 
</pre>
 
</pre>
 
</p>
 
</p>
 
<p>
 
<p>
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
+
To make answers appear in a certain order (e.g., Yes followed by No and Maybe), use <code>$mc->qa("question","Yes"); $mc->makeLast("Yes","No","Maybe");</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");
 
@ans = ("Yes","No");
 
@ans = ("Yes","No");
 
$pick = random(0,1,1);
 
$pick = random(0,1,1);
$cmc->new_checkbox_multiple_choice();
+
$mc->new_checkbox_multiple_choice();
$cmc->qa($quest[$pick],$ans[$pick]);
+
$mc->qa($quest[$pick],$ans[$pick]);
$cmc->makeLast("Yes","No");
+
$mc->makeLast("Yes","No","Maybe");
 
</pre>
 
</pre>
 
</p>
 
</p>
Line 96: Line 94:
 
BEGIN_TEXT
 
BEGIN_TEXT
   
This is a place to insert additional instructions.
 
  +
\{ $mc -> print_q() \}
 
$BR
 
$BR
$BR
 
  +
\{ $mc -> print_a() \}
\{ $cmc -> print_q() \}
 
$BR
 
\{ $cmc -> print_a() \}
 
   
 
END_TEXT
 
END_TEXT
Line 107: Line 102:
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
<b>Main Text:</b> Print the question and answers. Print the question text using <code>$cmc->print_q()</code> and
+
<b>Main Text:</b> Print the question and answers. Print the question text using <code>$mc->print_q()</code> and
the list of all answers using <code>$cmc->print_a()</code>.
+
the list of all answers using <code>$mc->print_a()</code>.
 
</p>
 
</p>
 
</td>
 
</td>
Line 119: Line 114:
 
$showPartialCorrectAnswers = 0;
 
$showPartialCorrectAnswers = 0;
   
ANS(checkbox_cmp($cmc->correct_ans));
+
ANS( checkbox_cmp( $mc->correct_ans() ) );
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 127: Line 122:
 
<b>Answer Evaluation:</b> We use the standard problem grader, an all-or-nothing grader that gives no partial credit, and set <code>$showPartialCorrectAnswers = 0;</code> 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 <code>checkbox_cmp</code> answer checker.
 
<b>Answer Evaluation:</b> We use the standard problem grader, an all-or-nothing grader that gives no partial credit, and set <code>$showPartialCorrectAnswers = 0;</code> 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 <code>checkbox_cmp</code> answer checker.
 
</p>
 
</p>
  +
<p>See
  +
[https://webwork.maa.org/moodle/mod/forum/discuss.php?d=4999 the linked forum discussion thread] for a technique to give partial credit on such questions.</p>
 
</td>
 
</td>
 
</tr>
 
</tr>

Revision as of 04:53, 17 January 2021

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.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();  

loadMacros(
"PGstandard.pl",
"PGchoicemacros.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

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

$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",                
"\( e^{ (x^3+1) / x } \)$BR",
);
$mc -> extra(
"\( \displaystyle \frac{ e^{x^2} }{ e^x } \)$BR",
"\( e^{x^2} + e^{1/x} \)$BR",
);
$mc -> makeLast("None of the above");

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

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, $mc->qa("question", "\( 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. 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);
$mc->new_checkbox_multiple_choice();
$mc->qa($quest[$pick],$ans[$pick]);
$mc->makeLast("Yes","No","Maybe");

BEGIN_TEXT

\{ $mc -> print_q() \}
$BR
\{ $mc -> print_a() \}

END_TEXT

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().

install_problem_grader(~~&std_problem_grader);

$showPartialCorrectAnswers = 0;

ANS( checkbox_cmp( $mc->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.

See the linked forum discussion thread for a technique to give partial credit on such questions.

Problem Techniques Index