help logoLON-CAPA Help


Custom Response is a way to have a problem graded based on an algorithm. The use of this response type is generally discouraged, since the responses will not be analyzable by the LON-CAPA statistics tools.

The student answer is stored in the variable $submission, and needs to be evaluated by Perl code inside the <answer>-tag. Custom Response needs to return a standard LON-CAPA. The most common response are:

The answer display is shown instead of the student response in 'show answer' mode. The following example illustrates this:
<problem>
<startouttext />Accept an answer of around 90 or -90<endouttext />
  <customresponse answerdisplay="something near 90 or -90">
    <answer type="loncapa/perl">
# We do not want a vector
if ($submission=~/\,/) { return 'EXTRA_ANSWER'; }
# Need a numerical answer here
if ($submission!~/^[\d\.\-\e]+$/i) { return 'WANTED_NUMERIC'; }
$difference=abs(90-abs($submission));
if ($difference==0) { return 'EXACT_ANS'; }
if ($difference < 0.1) { return 'APPROX_ANS'; }
return 'INCORRECT';</answer>
    <textline readonly="no" />
  </customresponse>
</problem>

Full list of possible return codes: