(Answer) (Category) LON-CAPA User Help : (Category) Authoring : (Category) Authoring Problems :
Specifying wrong answers for exam mode
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
[Append to This Answer]
Previous: (Answer) how to display variables that must be parsed first
Next: (Answer) multiple correct answers for String Response problems using Regular Expressions
This document is: http://help.loncapa.org/cgi-bin/fom?file=349
[Search] [Appearance] [Show This Answer As Text]
This is a Faq-O-Matic 2.719.
This FAQ administered by the LON-CAPA team at MSU. Submit a help request ticket to contact us.