Example code shows how wrong answers are coded into a numerical response problem.
<problem>
<script type="loncapa/perl">$a=&random(50,150,10); #width in cm
$b=&random(.5,3.0,.1); #length in m
$perimeter= 2*$a/100 + 2*$b;
# code to generate a randomly chosen wrong answer, while loop is used
# in case the correct answer is randomly chosen. This code does not
# protect against the scenarial where $randomWrong is equal to one of
# the other wrong answer though.
$randomWrong=&random($perimeter-.9,$perimeter*2,10);
while($randomWrong == $perimeter) {$randomWrong=&random($perimeter-.9,$perimeter*2,10)}
# All the possible wrong answers are put in the array below
# note that the maximum number of answer bubbles in order for LON-CAPA to use
# this array of wrong answer is equal to the number wrong answers plus 1 for
# the correct answer.
@wrongAnswers =( 2*$a+2*$b, $a+$b, $a/100+$b, $a*$b, $a*$b/100, $randomWrong);</script>
<startouttext />What is the perimeter of a rectangle with a width of <num format="0f">$a</num> cm and length of <num format="2f">$b</num> meters?<endouttext />
<numericalresponse unit="m" format="1f" answer="$perimeter" incorrect="@wrongAnswers">
<responseparam type="tolerance" default="5%" name="tol" description="Numerical Tolerance" />
<responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures" />
<responseparam name="numbubbles" type="int_pos" default="7" description="Number of bubbles in exam mode" />
<textline readonly="no" />
<hintgroup showoncorrect="no">
<startouttext />Make sure you are solving for the perimeter and not the area!<endouttext />
</hintgroup>
</numericalresponse>
</problem>felicia@lon-capa.org |