LON-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.
For a single textfield, the student's answer will be in a variable $submission. If the Custom Response has multiple textfields, the answers will be in an array
reference, and can be accessed as $$submission[0], $$submission[1], etc.
The student answer needs to be evaluated by Perl code inside the < answer > -tag. Custom Response needs to include an algorithm that determines and returns a standard LON-CAPA response. The most common LON-CAPA responses are:
- EXACT_ANS: return if solved exactly correctly
- APPROX_ANS: return if solved approximately
- INCORRECT: return if not correct, uses up a try
- ASSIGNED_SCORE: partial credit (also return the credit factor,
e.g. return(ASSIGNED_SCORE,0.3);)
- SIG_FAIL, NO_UNIT, EXTRA_ANSWER, MISSING_ANSWER, BAD_FORMULA,
WANTED_NUMERIC, WRONG_FORMAT: return if not correct for different reasons, does not use up a try
The answerdisplay is shown instead of the student response in 'show answer' mode after the answer date.
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">
# This examples uses perl 'regular expressions' for string evaluation.
# Consult a perl reference for help understanding the regular expressions.
# 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:
- EXACT_ANS: student is exactly correct
- APPROX_ANS: student is approximately correct
- NO_RESPONSE: student submitted no response
- MISSING_ANSWER: student submitted some but not all parts of a response
- EXTRA_ANSWER: student submitted a vector of values when a scalar was expected
- WANTED_NUMERIC: expected a numeric answer and didn't get one
- SIG_FAIL: incorrect number of Significant Figures
- UNIT_FAIL: incorrect unit
- UNIT_NOTNEEDED: submitted a unit when one shouldn't
- UNIT_INVALID_INSTRUCTOR: the unit provided by the author of the problem is unparsable
- UNIT_INVALID_STUDENT: the unit provided by the student is unparasable
- UNIT_IRRECONCIBLE: the unit from the student and the instructor are of different types
- NO_UNIT: needed a unit but none was submitted
- BAD_FORMULA: syntax error in submitted formula
- WRONG_FORMAT: student submission did not have the expected format
- INCORRECT: answer was wrong
- SUBMITTED: submission wasn't graded
- DRAFT: submission only stored
- MISORDERED_RANK: student submitted a poorly order rank response
- ERROR: unable to get a grade
- ASSIGNED_SCORE: partial credit; the customresponse needs to return the award followed by the partial credit factor
- TOO_LONG: answer submission was deemed too long
- INVALID_FILETYPE: student tried to upload a file that was of an extension that was not specifically allowed
- EXCESS_FILESIZE: student uploaded file(s) with a combined size that exceeded the amount allowed
- COMMA_FAIL: answer requires the use of comma grouping and it wasn't provided or was incorrect