Difference between revisions of "MultipleSelectProblems"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 1: Line 1:
<h2>Multiple Choice Problems: PG Code Snippet</h2>
+
<h2>Multiple Choice - Select All That Apply Problems: PG Code Snippet</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-choice questions in a problem. Note that these are <b>insertions</b>, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.</em>
+
<em>This code snippet shows the essential PG code to include multiple choice - select all that apply questions in a problem. A multiple choice question has only one correct answer, whereas a multiple choice - select all that apply question may require several choices to be selected at the same time to be correct. Note that these are <b>insertions</b>, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.</em>
 
</p>
 
</p>
   
 
<p>
 
<p>
Note that in this example we use old-style multiple choice answer objects. The new-style MathObjects have a multiple choice object as well, but its behavior is sufficiently different than that suggested here that is not documented here.
+
Note that in this example we use old-style multiple choice answer objects. The new-style MathObjects do not yet have a multiple choice - select all that apply object yet.
 
</p>
 
</p>
   
Line 21: Line 21:
 
<td style="background-color:#ddffdd;border:black 1px dashed;">
 
<td style="background-color:#ddffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
loadMacros("PGchoicemacros.pl");
 
  +
DOCUMENT();
  +
loadMacros(
  +
"PG.pl",
  +
"PGbasicmacros.pl",
  +
"PGchoicemacros.pl",
  +
"PGanswermacros.pl"
  +
);
  +
# Do not show which answers are incorrect.
  +
$showPartialCorrectAnswers = 0;
 
</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> in our list of loaded macro files.
+
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.
 
</p>
 
</p>
 
</td>
 
</td>
Line 33: Line 41:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
$mc = new_multiple_choice();
 
  +
# Make a new checkbox multiple choice
$mc->qa("What is your favorite color?", "blue");
 
  +
$cmc = new_checkbox_multiple_choice();
$mc->extra("red","green");
 
  +
# $cmc now "contains" the checkbox multiple choice object.
$mc->makeLast("none of the above");
 
  +
  +
# Insert a question and matching answers in the q/a list
  +
$cmc -> qa (
  +
"Please select all vectors that are named.", # question
  +
"\(\vec{a} = \langle 1, 1, 1 \rangle \)", # a correct answer
  +
"\(\vec{n} = \langle 1, -1, 0 \rangle \)", # another correct answer
  +
"\(\vec{z} = \langle 0, 0, 0 \rangle \)", # Use " ... " to enter a string
  +
);
  +
  +
  +
# Insert some incorrect answers
  +
$cmc -> extra(
  +
"\(\langle -2, 2, 2 \rangle\)",
  +
"\(\langle \pi, 4, -1 \rangle\)",
  +
);
  +
  +
$cmc->makeLast("None of the above");
 
</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 multiple choice object with <code>new_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.
+
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.
 
</p>
 
</p>
 
</td>
 
</td>

Revision as of 21:48, 4 October 2009

Multiple Choice - Select All That Apply Problems: PG Code Snippet

This code snippet shows the essential PG code to include multiple choice - select all that apply questions in a problem. A multiple choice question has only one correct answer, whereas a multiple choice - select all that apply question may require several choices to be selected at the same time to be correct. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.

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

Problem Techniques Index

PG problem file Explanation
DOCUMENT();  
loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl"
);
# Do not show which answers are incorrect.
$showPartialCorrectAnswers = 0;

In the initialization section of the file we need to include PGchoicemacros.pl and PGanswermacros.pl in our list of loaded macro files. We should also set $showPartialCorrectAnswers = 0; to hide the correct answers from students until they have answered everything correctly.

# Make a new checkbox multiple choice
$cmc = new_checkbox_multiple_choice();
# $cmc now "contains" the checkbox multiple choice object. 

# Insert a question and matching answers in the q/a list
$cmc -> qa (
"Please select all vectors that are named.",  # question
"\(\vec{a} = \langle 1, 1, 1 \rangle \)", # a correct answer
"\(\vec{n} = \langle 1, -1, 0 \rangle \)", # another correct answer                
"\(\vec{z} = \langle 0, 0, 0 \rangle \)", # Use " ... " to enter a string
);


# Insert some incorrect answers
$cmc -> extra(
"\(\langle -2, 2, 2 \rangle\)",
"\(\langle \pi, 4, -1 \rangle\)",
);

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

In the problem set-up, we create a new checkbox multiple choice object with new_checkbox_multiple_choice, and then store the question and correct answer with the qa method. Other answers are specified as a list of arguments to the extra method. To force an answer (either a new extra answer, or the correct answer) to appear last in the list of options, use the makeLast method. All other answers will be scrambled when the multiple choice problem is shown to students.

  BEGIN_TEXT
  \{ $mc->print_q() \}
  \{ $mc->print_a() \}
  END_TEXT

In the text section we print the question and answers.

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

And we grade the problem with radio_cmp.

Problem Techniques Index