[LON-CAPA-users] Having an equation or a range as a response
Gerd Kortemeyer
korte at lite.msu.edu
Thu Jan 19 21:51:53 EST 2012
Hi,
On Jan 19, 2012, at 8:39 PM, Seema Ali wrote:
> An example would be:
>
> State the equation for the asymptote for the graph y=10^(x+7)+8.
> Answer: [answer box]
>
> I would like the student to enter the entire equation into the answer box.
So that would be x=7 or y=8, correct?
<problem>
<script type="loncapa/perl">$a=&random(3,8,1);
$b=$a+&random(2,5,1);
$sample="x=$a or y=$b would be correct";
</script>
<startouttext />
Given an equation for an asymptote of <m eval="on">$y=10^{x+$a}+$b$</m>.
<endouttext />
<customresponse answerdisplay="$sample">
<answer type="loncapa/perl">
# Get left and right side of equation
($left,$right)=split(/\s*\=\s*/,$submission);
# We want something on both sides of the equation
unless (($left=~/\w/) && ($right=~/\w/)) { return 'BAD_FORMULA'; }
# Use computer algebra system to see if it agrees to one of our desired equations
if (&cas('maxima',"($left)-($right)-(x-$a)") eq '0') { return 'EXACT_ANS'; }
if (&cas('maxima',"($left)-($right)-(y-$b)") eq '0') { return 'EXACT_ANS'; }
# Too bad ...
return 'INCORRECT';
</answer>
<textline readonly="no" />
</customresponse>
</problem>
Let me know if that does the trick.
- Gerd.
More information about the LON-CAPA-users
mailing list