Hello,
I have a style question.
I've pasted a minimal example below for new_checkbox_multiple_choice() that does the following: randomly selects 3 entries from an array of 4 correct answers and randomly selects entries 3 from an array of 4 wrong answers to be displayed as options for the students to select.
Is there a smarter/easier way to accomplish what I've done? As far I can tell, there's no built in option in new_checkbox_multiple_choice() to accomplish this task.
########################################################################
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"PGchoicemacros.pl",
"PGcourse.pl",
);
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
###########################
# Setup
@correct = (
"correct1 $BR",
"correct2 $BR",
"correct3 $BR",
"correct4 $BR",
);
$num_cor =3;
@temp_cor = (0..$#correct); #array of indices of @correct
@slice_cor = (map { splice(@temp_cor, random(0, $#temp_cor), 1) } 1 .. $num_cor);
#randomly select $num_cor correct options to display
@cor_print = @correct[@slice_cor];
@wrong = (
"wrong1 $BR",
"wrong2 $BR",
"wrong3 $BR",
"wrong4 $BR"
);
$num_wrg =3;
@temp_wrg = (0..$#wrong); #array of indices of @wrong
@slice_wrg = (map { splice(@temp_wrg, random(0, $#temp_wrg), 1) } 1 .. $num_wrg);
#randomly select $num_wrg wrong options to display
@wrg_print = @wrong[@slice_wrg];
$mc = new_checkbox_multiple_choice();
$mc -> qa (
"From the list below, select every sentence that must be true.",
$cor_print[0],
$cor_print[1],
$cor_print[2],
);
$mc -> extra(
$wrg_print[0],
$wrg_print[1],
$wrg_print[2],
);
#$mc -> makeLast("None of the above");
###########################
# Main text
BEGIN_PGML
[@ $mc -> print_q() @]***
[@ $mc -> print_a() @]***
END_PGML
############################
# Answer evaluation
# All or nothing grader
install_problem_grader(~~&std_problem_grader);
# Show which answers are correct and which ones are incorrect, set to 0 for no information
$showPartialCorrectAnswers = 0;
ANS( checkbox_cmp( $mc->correct_ans() ) );
############################
# Solution
BEGIN_PGML_SOLUTION
The correct answer is [$mc->correct_ans()].
END_PGML_SOLUTION
COMMENT('Uses PGML and Math Objects.');
ENDDOCUMENT();