Difference between revisions of "MultipleSelectProblems"
(40 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | <h2>Multiple Select Problems (or Checkbox Multiple Choice or Select All That Apply): PG Code Snippet</h2> |
||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/Misc/MultipleChoiceCheckbox.html a newer version of this problem]</p> |
||
+ | |||
+ | <h2>Multiple Select Problems (or Checkbox Multiple Choice or Select All That Apply)</h2> |
||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
− | <em>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. |
+ | <em>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. </em> |
</p> |
</p> |
||
<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 |
+ | 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 22: | Line 26: | ||
<pre> |
<pre> |
||
DOCUMENT(); |
DOCUMENT(); |
||
+ | |||
loadMacros( |
loadMacros( |
||
− | " |
+ | "PGstandard.pl", |
− | "PGbasicmacros.pl", |
||
"PGchoicemacros.pl", |
"PGchoicemacros.pl", |
||
− | "PGanswermacros.pl" |
||
+ | "PGcourse.pl", |
||
); |
); |
||
− | # Do not show which answers are incorrect. |
||
+ | |||
− | $showPartialCorrectAnswers = 0; |
||
+ | TEXT(beginproblem()); |
||
</pre> |
</pre> |
||
</td> |
</td> |
||
<td style="background-color:#ccffcc;padding:7px;"> |
<td style="background-color:#ccffcc;padding:7px;"> |
||
<p> |
<p> |
||
− | In the initialization section of the file we need to include <code>PGchoicemacros.pl</code> and <code>PGanswermacros.pl</code> in our list of loaded macro files. We should also set <code>$showPartialCorrectAnswers = 0;</code> to hide the correct answers from students until they have answered everything correctly. |
||
+ | <b>Initialization:</b> We must load <code>PGchoicemacros.pl</code> and <code>PGanswermacros.pl</code>. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 40: | Line 45: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | # Make a new checkbox multiple choice |
||
+ | $mc = new_checkbox_multiple_choice(); |
||
− | $cmc = new_checkbox_multiple_choice(); |
||
+ | $mc -> qa ( |
||
− | # $cmc now "contains" the checkbox multiple choice object. |
||
+ | "Select all expressions that are equivalent to |
||
− | |||
+ | \( e^{x^2 + 1/x} \). There may be more than |
||
− | # Insert a question and matching answers in the q/a list |
||
+ | one correct answer.", |
||
− | $cmc -> qa ( |
||
+ | "\( e^{x^2} e^{1/x} \)$BR", |
||
− | "Please select all vectors that are named.", # question |
||
+ | "\( e^{x^2} e^{x^{-1}} \)$BR", |
||
− | "\(\vec{a} = \langle 1, 1, 1 \rangle \)", # a correct answer |
||
+ | "\( e^{ (x^3+1) / x } \)$BR", |
||
− | "\(\vec{n} = \langle 1, -1, 0 \rangle \)", # another correct answer |
||
− | "\(\vec{z} = \langle 0, 0, 0 \rangle \)", # Use " ... " to enter a string |
||
); |
); |
||
− | |||
+ | $mc -> extra( |
||
− | |||
+ | "\( \displaystyle \frac{ e^{x^2} }{ e^x } \)$BR", |
||
− | # Insert some incorrect answers |
||
+ | "\( e^{x^2} + e^{1/x} \)$BR", |
||
− | $cmc -> extra( |
||
− | "\(\langle -2, 2, 2 \rangle\)", |
||
− | "\(\langle \pi, 4, -1 \rangle\)", |
||
); |
); |
||
− | |||
+ | $mc -> makeLast("None of the above"); |
||
− | $cmc->makeLast("None of the above"); |
||
− | |||
− | # Note that unlike match lists and select lists, you cannot call qa() again |
||
</pre> |
</pre> |
||
</td> |
</td> |
||
<td style="background-color:#ffffcc;padding:7px;"> |
<td style="background-color:#ffffcc;padding:7px;"> |
||
<p> |
<p> |
||
− | In the problem set-up, we create a new checkbox multiple choice object with <code>new_checkbox_multiple_choice</code>, and then store the question and correct answer with the <code>qa</code> method. Other answers are specified as a list of arguments to the <code>extra</code> method. 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 other answers will be scrambled when the multiple choice problem is shown to students. |
||
+ | <b>Setup:</b> |
||
+ | Create a new checkbox multiple choice object named <code>$mc</code> with <code>$mc->new_checkbox_multiple_choice();</code>. |
||
+ | </p> |
||
+ | <p> |
||
+ | 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> |
||
+ | Incorrect answers are specified as a list of string arguments to the <code>extra( )</code> method. |
||
+ | </p> |
||
+ | <p> |
||
+ | 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> |
||
+ | $mc->qa("question","None of the above"); |
||
+ | $mc->extra("very wrong","distractor","red herring"); |
||
+ | $mc->makeLast("None of the above"); |
||
+ | </pre> |
||
+ | </p> |
||
+ | <p> |
||
+ | 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> |
||
+ | @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"); |
||
+ | </pre> |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 73: | Line 97: | ||
<td style="background-color:#ffdddd;border:black 1px dashed;"> |
<td style="background-color:#ffdddd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | TEXT(beginproblem()); |
||
+ | BEGIN_TEXT |
||
− | # Print the text using $cmc->print_q() for the questions and |
||
+ | \{ $mc -> print_q() \} |
||
− | # $cmc->print_a() to print the answers. |
||
+ | $BR |
||
− | BEGIN_TEXT |
||
+ | \{ $mc -> print_a() \} |
||
− | This is the place to insert additional text if you wish. |
||
− | $PAR |
||
− | \{ $cmc -> print_q() \} |
||
− | $PAR |
||
− | \{ $cmc -> print_a() \} |
||
END_TEXT |
END_TEXT |
||
</pre> |
</pre> |
||
<td style="background-color:#ffcccc;padding:7px;"> |
<td style="background-color:#ffcccc;padding:7px;"> |
||
<p> |
<p> |
||
− | In the text section we print the question and answers. |
||
+ | <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>$mc->print_a()</code>. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 95: | Line 115: | ||
<td style="background-color:#eeddff;border:black 1px dashed;"> |
<td style="background-color:#eeddff;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | # Enter the correct answers to be checked against the answers to the students. |
||
+ | install_problem_grader(~~&std_problem_grader); |
||
− | ANS(checkbox_cmp( $cmc->correct_ans ) ) ; |
||
+ | |||
+ | $showPartialCorrectAnswers = 0; |
||
+ | |||
+ | ANS( checkbox_cmp( $mc->correct_ans() ) ); |
||
ENDDOCUMENT(); |
ENDDOCUMENT(); |
||
Line 102: | Line 125: | ||
<td style="background-color:#eeccff;padding:7px;"> |
<td style="background-color:#eeccff;padding:7px;"> |
||
<p> |
<p> |
||
− | And we grade the problem with <code>checkbox_cmp</code>. |
||
+ | <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> |
Latest revision as of 10:36, 16 July 2023
This problem has been replaced with a newer version of this problem
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.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "PGchoicemacros.pl", "PGcourse.pl", ); TEXT(beginproblem()); |
Initialization: We must load |
$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
Use the question and answer method
Incorrect answers are specified as a list of string arguments to the
The arguments of the $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 @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 |
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 See the linked forum discussion thread for a technique to give partial credit on such questions. |