Difference between revisions of "MultipleChoiceProblems"

From WeBWorK_wiki
Jump to navigation Jump to search
(added historical tag and gave updated problem link)
 
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  +
{{historical}}
  +
  +
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with three alternatives: </p>
  +
  +
* [https://openwebwork.github.io/pg-docs/sample-problems/Misc/MultipleChoiceCheckbox.html Multiple choice with checkboxes]
  +
* [https://openwebwork.github.io/pg-docs/sample-problems/Misc/MultipleChoicePopup.html Multiple choice with popups]
  +
* [https://openwebwork.github.io/pg-docs/sample-problems/Misc/MultipleChoiceRadio.html Multiple choice with radio buttons]
  +
 
<h2>Multiple Choice Problems: PG Code Snippet</h2>
 
<h2>Multiple Choice 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 a multiple-choice question in a problem.</em>
  +
<br />
  +
<br />
  +
For an example of a multiple choice problem in which the choices are graphs, see Example 1 of [http://webwork.maa.org/wiki/GraphsInTables GraphsInTables]
 
</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.
 
  +
We give two examples here. The first uses old-style answer checkers; the second newer parser based code. Note that the functionality that is provided in either case is different; the latter is syntactically cleaner and simpler, but doesn't have the same range of functions provided by the first. See also the [[PopUpLists|Pop Up Lists]] page.
 
</p>
 
</p>
   
 
<p style="text-align:center;">
 
<p style="text-align:center;">
[[IndexOfProblemTechniques|Problem Techniques Index]]
+
[[Problem_Techniques|Problem Techniques Index]]
  +
</p>
  +
  +
<p>
  +
<strong>With Old-Style Answer Checkers</strong>
 
</p>
 
</p>
   
Line 21: Line 29:
 
<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(
  +
"PGstandard.pl",
  +
"PGchoicemacros.pl",
  +
);
  +
 
</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.
+
<b>Initialization:</b> Include <code>PGchoicemacros.pl</code> in the list of loaded macro files.
 
</p>
 
</p>
 
</td>
 
</td>
Line 33: Line 47:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
$mc = new_multiple_choice();
+
$mc = new_multiple_choice();
$mc->qa("What is your favorite color?", "blue");
+
$mc->qa(
$mc->extra("red","green");
+
"What is your favorite color?",
$mc->makeLast("none of the above");
+
"blue"
  +
);
  +
$mc->extra(
  +
"red",
  +
"green",
  +
);
  +
$mc->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.
+
<b>Setup:</b> 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.
  +
</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. Note that if we have a list of questions (and correct answers) it is easy to randomly pick one to display. For example, if we want to pick between the questions "How many legs do cats have?" and "How many legs to ostriches have?", we could use the following:
  +
<pre>
  +
@quest = ("How many legs do cats have?",
  +
"How many legs to ostriches have?");
  +
@ans = ("4","2");
  +
$pick = random(0,1,1);
  +
$mc->new_checkbox_multiple_choice();
  +
$mc->qa($quest[$pick],$ans[$pick]);
  +
$mc->makeLast("2","4","None of the above");
  +
</pre>
 
</p>
 
</p>
 
</td>
 
</td>
Line 48: Line 62:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
BEGIN_TEXT
+
BEGIN_TEXT
\{ $mc->print_q() \}
+
\{ $mc->print_q() \}
\{ $mc->print_a() \}
+
$BR
END_TEXT
+
\{ $mc->print_a() \}
  +
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> In the text section we print the question and answers.
 
</p>
 
</p>
 
</td>
 
</td>
Line 62: Line 76:
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
<pre>
ANS( radio_cmp( $mc->correct_ans() ) );
 
  +
$showPartialCorrectAnswers = 0;
  +
  +
ANS( radio_cmp( $mc->correct_ans() ) );
  +
  +
ENDDOCUMENT();
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<p>
And we grade the problem with <code>radio_cmp</code>.
 
  +
<b>Answer Evaluation:</b> In most cases we will want to set <code>$showPartialCorrectAnswers</code> to <code>0</code> (false) for multiple choice problems. Otherwise, students can use the feedback or the partial credit received to guess and check if their answers are correct.
  +
We grade the problem with <code>radio_cmp</code>.
 
</p>
 
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
  +
  +
<p>
  +
<strong>With Newer Answer Checkers</strong>
  +
</p>
  +
  +
<table cellspacing="0" cellpadding="2" border="0">
  +
<tr valign="top">
  +
<th> PG problem file </th>
  +
<th> Explanation </th>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ddffdd;border:black 1px dashed;">
  +
<pre>
  +
DOCUMENT();
  +
  +
loadMacros(
  +
"PGstandard.pl",
  +
"parserRadioButtons.pl",
  +
);
  +
  +
</pre>
  +
</td>
  +
<td style="background-color:#ccffcc;padding:7px;">
  +
<p>
  +
<b>Initialization:</b> Include <code>parserRadioButtons.pl</code> in the list of loaded macro files. This allows use of radio buttons (all options are shown, with a select-one button in front of each). We could also use <code>parserPopUp.pl</code> instead, which would allow creation of a drop-down menu of options. This is noted below as well, and is documented separately on the [[PopUpLists|Pop Up Lists]] page.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffffdd;border:black 1px dashed;">
  +
<pre>
  +
$mc = RadioButtons(
  +
[ "\( \sin(x) \)", "\( \tan(x) \)", "\( e^x \)", "None of these" ],
  +
"\( e^x \)",
  +
last => ["None of these"],
  +
labels => ["Sine", "Tangent", "Exponential", "None of these"] );
  +
</pre>
  +
</td>
  +
<td style="background-color:#ffffcc;padding:7px;">
  +
<p>
  +
<b>Setup:</b> We create a radio button object with <code>RadioButtons</code>. The first argument is a reference to a list of options: <code>["Blue","Red",...]</code>, and the second is the correct answer, which needs to be one of the options. The last argument, <code>last=>["None of these"]</code>, specifies an option (or comma separated list of options) to always display last. Since the list of answers contains math typeset by LaTeX, the <code>labels</code> option must be specified with a plain text substitute for display purposes. The labels can be set to A, B, C,... or 1, 2, 3,... by specifying <code>labels => "ABC"</code> or <code>labels => "123"</code>.
  +
</p>
  +
<p>
  +
To create a drop-down ("pop-up") option (having loaded <code>parserPopUp.pl</code>, of course), we use the same syntax:
  +
</p>
  +
<pre>
  +
$mc = PopUp(
  +
[ "?", "Blue", "Red", "Green",
  +
"None of the above" ],
  +
"Blue" );
  +
</pre>
  +
<p>
  +
Note that in this case we should specify a generic non-answer as the first option, so that when the selector is displayed it does not automatically give the student an answer (which may or may not be correct).
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
BEGIN_TEXT
  +
Which function has a horizontal asymptote?
  +
$BR
  +
\{ $mc->buttons() \}
  +
END_TEXT
  +
</pre>
  +
<td style="background-color:#ffcccc;padding:7px;">
  +
<p>
  +
<b>Main text:</b> In the text section we print the question and radio buttons giving the answers. For a PopUp object, the call to create the menu of options is <code>$mc->menu()</code>.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#eeddff;border:black 1px dashed;">
  +
<pre>
  +
$showPartialCorrectAnswers = 0;
  +
  +
ANS( $mc->cmp() );
  +
  +
ENDDOCUMENT();
  +
</pre>
  +
<td style="background-color:#eeccff;padding:7px;">
  +
<p>
  +
<b>Answer Evaluation:</b> In most cases we will want to set <code>$showPartialCorrectAnswers</code> to <code>0</code> (false) for multiple choice problems. Otherwise, students can use the feedback or the partial credit received to guess and check if their answers are correct.
  +
We grade the problem as expected.
  +
</p>
  +
</td>
  +
</tr>
  +
</table>
  +
   
 
<p style="text-align:center;">
 
<p style="text-align:center;">
[[IndexOfProblemTechniques|Problem Techniques Index]]
+
[[Problem_Techniques|Problem Techniques Index]]
 
</p>
 
</p>
   

Latest revision as of 11:56, 29 June 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with three alternatives:

Multiple Choice Problems: PG Code Snippet

This code snippet shows the essential PG code to include a multiple-choice question in a problem.

For an example of a multiple choice problem in which the choices are graphs, see Example 1 of GraphsInTables

We give two examples here. The first uses old-style answer checkers; the second newer parser based code. Note that the functionality that is provided in either case is different; the latter is syntactically cleaner and simpler, but doesn't have the same range of functions provided by the first. See also the Pop Up Lists page.

Problem Techniques Index

With Old-Style Answer Checkers

PG problem file Explanation
DOCUMENT();  

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

Initialization: Include PGchoicemacros.pl in the list of loaded macro files.

$mc = new_multiple_choice();
$mc->qa(
"What is your favorite color?", 
"blue"
);
$mc->extra(
"red",
"green",
);
$mc->makeLast("none of the above");

Setup: Create a new multiple choice object with new_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.

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. Note that if we have a list of questions (and correct answers) it is easy to randomly pick one to display. For example, if we want to pick between the questions "How many legs do cats have?" and "How many legs to ostriches have?", we could use the following:

@quest = ("How many legs do cats have?",
     "How many legs to ostriches have?"); 
@ans = ("4","2"); 
$pick = random(0,1,1);
$mc->new_checkbox_multiple_choice();
$mc->qa($quest[$pick],$ans[$pick]);
$mc->makeLast("2","4","None of the above");

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

Main text: In the text section we print the question and answers.

$showPartialCorrectAnswers = 0;

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

ENDDOCUMENT();

Answer Evaluation: In most cases we will want to set $showPartialCorrectAnswers to 0 (false) for multiple choice problems. Otherwise, students can use the feedback or the partial credit received to guess and check if their answers are correct. We grade the problem with radio_cmp.

With Newer Answer Checkers

PG problem file Explanation
DOCUMENT();  

loadMacros(
"PGstandard.pl",
"parserRadioButtons.pl",
);

Initialization: Include parserRadioButtons.pl in the list of loaded macro files. This allows use of radio buttons (all options are shown, with a select-one button in front of each). We could also use parserPopUp.pl instead, which would allow creation of a drop-down menu of options. This is noted below as well, and is documented separately on the Pop Up Lists page.

$mc = RadioButtons(
    [ "\( \sin(x) \)", "\( \tan(x) \)", "\( e^x \)", "None of these" ],
    "\( e^x \)",
    last => ["None of these"],
    labels => ["Sine", "Tangent", "Exponential", "None of these"] );

Setup: We create a radio button object with RadioButtons. The first argument is a reference to a list of options: ["Blue","Red",...], and the second is the correct answer, which needs to be one of the options. The last argument, last=>["None of these"], specifies an option (or comma separated list of options) to always display last. Since the list of answers contains math typeset by LaTeX, the labels option must be specified with a plain text substitute for display purposes. The labels can be set to A, B, C,... or 1, 2, 3,... by specifying labels => "ABC" or labels => "123".

To create a drop-down ("pop-up") option (having loaded parserPopUp.pl, of course), we use the same syntax:

  $mc = PopUp(
    [ "?", "Blue", "Red", "Green",
      "None of the above" ],
    "Blue" );

Note that in this case we should specify a generic non-answer as the first option, so that when the selector is displayed it does not automatically give the student an answer (which may or may not be correct).

BEGIN_TEXT
Which function has a horizontal asymptote?
$BR
\{ $mc->buttons() \}
END_TEXT

Main text: In the text section we print the question and radio buttons giving the answers. For a PopUp object, the call to create the menu of options is $mc->menu().

$showPartialCorrectAnswers = 0;

ANS( $mc->cmp() );

ENDDOCUMENT();

Answer Evaluation: In most cases we will want to set $showPartialCorrectAnswers to 0 (false) for multiple choice problems. Otherwise, students can use the feedback or the partial credit received to guess and check if their answers are correct. We grade the problem as expected.


Problem Techniques Index