Difference between revisions of "MultipleChoiceProblems"

From WeBWorK_wiki
Jump to navigation Jump to search
m
m
Line 36: Line 36:
 
<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 57: Line 57:
 
<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>
  +
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>
 
</p>
 
</td>
 
</td>
Line 74: Line 74:
 
<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 91: Line 91:
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<p>
Use the standard problem grader to give credit only if all answers are correct, and do not give feedback on partial correct answers. Otherwise, students can use the feedback or the partial credit received to guess and check if their answers are correct.
+
<b>Answer Evaluation:</b> Use the standard problem grader to give credit only if all answers are correct, and do not give feedback on partial correct answers. 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>.
 
We grade the problem with <code>radio_cmp</code>.
 
</p>
 
</p>

Revision as of 13:09, 2 January 2010

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
DOCUMENT();  

loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

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. 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: In the text section we print the question and answers.

install_problem_grader(~~&std_problem_grader);

$showPartialCorrectAnswers = 0;

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

ENDDOCUMENT();

Answer Evaluation: Use the standard problem grader to give credit only if all answers are correct, and do not give feedback on partial correct answers. 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.

Problem Techniques Index