[LON-CAPA-users] Preprocessor vs. Custom Response

Gerd Kortemeyer kortemey at msu.edu
Fri Dec 4 15:32:10 EST 2015


> On Dec 4, 2015, at 2:41 PM, Jacob Bond <bond13 at purdue.edu> wrote:
>> Are you actually looking for the fraction to be reduced? Because we can check that very generally. 
> Yes, that is the main idea.

Okay, then I would use Maxima to figure out if the reduced fraction is equal to the fraction input by the student, see below.

- Gerd.

<script type="loncapa/perl">

<startouttext />
Input $a/$b as a reduced fraction.
<endouttext />

<customresponse answerdisplay="$reduced">

<answer type="loncapa/perl"># Split nominator and denominator
# Do we have a nominator? If not, be nice and don't charge a try
unless ($nominator) { return 'BAD_FORMULA'; }
# Is it valid? If not, don't charge a try
if ($nominator=~/^Error/i) { return 'BAD_FORMULA'; }
# If students just input a number, there would be no denominator
unless ($denominator) {
# Check for exact numerical equivalency:
   if ($nominator==$numerical) { return 'EXACT_ANS'; }
} else {
# There is a denominator
# Again, be nice and don't charge a try for syntax errors
   if ($denominator=~/^Error/i) { return 'BAD_FORMULA'; }
# Okay, let's compare the fractions as strings
    if ("$nominator/$denominator" eq $reduced) { return 'EXACT_ANS'; }
# Nope, sorry.
return 'INCORRECT';</answer>

    <textline readonly="no" spellcheck="none" />


More information about the LON-CAPA-users mailing list