Here is a simple multiple choice question: identify the interval
containing
. In this set up, we introduce a permutation so that
even though the answers are fixed, the correct answer will not
necessarily be the same for all students.
The snippet of code is below. This is a good deal simpler than the
matching questions, and hopefully the code is clear. Once again we
have to retrieve the answer from an ordered list. The correct answer
is $answers[1] (the second answer!). The letters are listed with
$ALPHABET[i] corresponding to
$answers[
(i)], so $answers[1] corresponds
to $ALPHABET[
(1)].
@answers = ("the interval \( [2, 3) \)",
"the interval \( [3, 4) \)",
"the interval \( [4, 5) \)",
"the interval \( [5, 6) \)");
## A list consisting of 0, 1, 2, 3 in "random" order.
@permutation = NchooseK(4,4);
## Ok, we are ready to begin...
##
TEXT(beginproblem());
BEGIN_TEXT
$BR
The real number \( \pi \) is which interval? \{ans_rule(10)\}
$BR
END_TEXT
TEXT(OL(@answers[@permutation]));
@inverted_alphabet = @ALPHABET[invert(@permutation)];
## The answer is $answers[1]
ANS(std_str_cmp($inverted_alphabet[1]));