Difference between revisions of "MultipleSelectProblems"

From WeBWorK_wiki
Jump to navigation Jump to search
m
m
Line 105: Line 105:
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
<pre>
ANS(checkbox_cmp($cmc->correct_ans));
 
  +
install_problem_grader(~~&std_problem_grader);
   
 
$showPartialCorrectAnswers = 0;
 
$showPartialCorrectAnswers = 0;
  +
  +
ANS(checkbox_cmp($cmc->correct_ans));
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 113: Line 115:
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<p>
Answer Evaluation: Grade the problem with <code>checkbox_cmp</code>. We set <code>$showPartialCorrectAnswers = 0;</code> to hide the correct answers from students until they have answered everything correctly.
+
Answer Evaluation: Grade the problem with <code>checkbox_cmp</code>. We use the standard problem grader and set <code>$showPartialCorrectAnswers = 0;</code> to hide the correct answers and withhold credit until all answers are correct.
 
</p>
 
</p>
 
</td>
 
</td>

Revision as of 19:04, 7 November 2009

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 yet.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();  
loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl"
);

Initialization: We must load PGchoicemacros.pl and PGanswermacros.pl.

# 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 expressions that are equivalent to \(e^{x^2 + 1/x}\).",  # question
"\( e^{x^2} e^{1/x} \)", # a correct answer
"\( e^{x^2} e^{x^{-1}} \)", # another correct answer                
"\( e^{ (x^3+1) / x } \)", # Use " ... " to enter a string and \( \) for math
# "All of the above",
# "None of the above", 
);
# If the only correct answer is "All of the above"
# or "None of the above", uncomment the 
# "All of the above" or "None of the above" string 
# above and remove all other correct answers from the list


# Insert some incorrect answers
$cmc -> extra(
"\( e^{ (x^2+1) / x } \)",
"\( e^{x^2} e^{-x} \)",
"\( e^{x^2} e^{-x} \)",
"\( \displaystyle \frac{ e^{x^2} }{ e^x } \)",
"\( e^{x^2} + e^{1/x} \)",
"\( e^{x^2} + e^{-x} \)",
);

# The next line can be uncommented.
# $cmc->makeLast("All of the above");

# Note that unlike match lists and select lists, you cannot call qa() again

Setup: 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.

TEXT(beginproblem());

# Print the text using $cmc->print_q() for the questions and
# $cmc->print_a() to print the answers.
BEGIN_TEXT

This is a place to insert additional text if you wish.
$PAR
\{ $cmc -> print_q() \}
$PAR
\{ $cmc -> print_a() \}
END_TEXT

Main Text: Print the question and answers.

install_problem_grader(~~&std_problem_grader);

$showPartialCorrectAnswers = 0;

ANS(checkbox_cmp($cmc->correct_ans));

ENDDOCUMENT();

Answer Evaluation: Grade the problem with checkbox_cmp. We use the standard problem grader and set $showPartialCorrectAnswers = 0; to hide the correct answers and withhold credit until all answers are correct.

Problem Techniques Index