Difference between revisions of "MultipleSelectProblems"

From WeBWorK_wiki
Jump to navigation Jump to search
(New page: Test)
 
Line 1: Line 1:
Test
 
  +
<h2>Multiple Choice Problems: PG Code Snippet</h2>
  +
  +
<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>
  +
</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.
  +
</p>
  +
  +
<p style="text-align:center;">
  +
[[IndexOfProblemTechniques|Problem Techniques Index]]
  +
</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>
  +
loadMacros("PGchoicemacros.pl");
  +
</pre>
  +
</td>
  +
<td style="background-color:#ccffcc;padding:7px;">
  +
<p>
  +
In the initialization section of the file we need to include <code>PGchoicemacros.pl</code> in our list of loaded macro files.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffffdd;border:black 1px dashed;">
  +
<pre>
  +
$mc = new_multiple_choice();
  +
$mc->qa("What is your favorite color?", "blue");
  +
$mc->extra("red","green");
  +
$mc->makeLast("none of the above");
  +
</pre>
  +
</td>
  +
<td style="background-color:#ffffcc;padding:7px;">
  +
<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.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
BEGIN_TEXT
  +
\{ $mc->print_q() \}
  +
\{ $mc->print_a() \}
  +
END_TEXT
  +
</pre>
  +
<td style="background-color:#ffcccc;padding:7px;">
  +
<p>
  +
In the text section we print the question and answers.
  +
</p>
  +
</td>
  +
</tr>
  +
<tr valign="top">
  +
<td style="background-color:#eeddff;border:black 1px dashed;">
  +
<pre>
  +
ANS( radio_cmp( $mc->correct_ans() ) );
  +
</pre>
  +
<td style="background-color:#eeccff;padding:7px;">
  +
<p>
  +
And we grade the problem with <code>radio_cmp</code>.
  +
</p>
  +
</td>
  +
</tr>
  +
</table>
  +
  +
<p style="text-align:center;">
  +
[[IndexOfProblemTechniques|Problem Techniques Index]]
  +
</p>
  +
  +
[[Category:Problem Techniques]]

Revision as of 21:32, 4 October 2009

Multiple Choice Problems: PG Code Snippet

This code snippet shows the essential PG code to include multiple-choice questions in a problem. 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 have a multiple choice object as well, but its behavior is sufficiently different than that suggested here that is not documented here.

Problem Techniques Index

PG problem file Explanation
  loadMacros("PGchoicemacros.pl");

In the initialization section of the file we need to include PGchoicemacros.pl in our 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");

In the problem set-up, we 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.

  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