Skip to content
Classroom

Question Types

The answer type decides what input box a student gets and how their response is graded.

The syntax these pages used to show does not exist

Earlier versions documented a bracketed-section syntax — [calculated], answer = x^2 + 1;, simplify = full;. None of it is real. The engine has no bracketed sections, settings are $variables with a dollar sign, and the answer type is not written in the code at all.

The real model is below. It applies to every page in this section.

How a question is actually put together

A question is a record with an answer type and some text fields. The question editor has three boxes:

Editor box Stored as What goes in it
Common Control control All code: randomization, variable definitions, computing $answer, and every option variable. Runs before the question text is built.
Question Text qtext The question as displayed. AsciiMath in backticks; interpolates $variables.
Detailed Solution solution The worked solution; interpolates $variables. While empty it is hidden behind an Add a detailed solution link. Three checkboxes sit under it. Tick "Uses random variables from the question, or question is not randomized" whenever that is true; left unticked, a solution shown with "Show Answer" is prefixed "This solution is for a similar problem, not your specific version". The other two decide whether it is offered as a "written example" help link and/or shown with "Show Answer".

The record also has two legacy columns, qcontrol and answer, used by older questions. The editor has no box for them: when you open such a question, their code is appended to Common Control, and saving stores it there. (qcontrol is not re-run when the answer is scored, which is one reason not to rely on it.)

The answer type is a property of the question, not a line of code

The engine reads it from the question record and passes it to the interpreter before your code runs. You choose it from the type selector in the editor; you never write it, and you cannot set it from code — $anstype is a reserved name and assigning to it fails the question with Eeek.. unallowed var.

Multipart questions follow the same rule: choose Multipart (type name multipart) in the type selector, then list each part's type in $anstypes (plural) — see Multipart. In a question of any other type except conditional, $anstypes is ignored.

Options are variables you set in Common Control

Everything that tunes grading or display is an ordinary variable. The engine collects whichever ones you have defined.

$answer = 42
$reqdecimals = 2
$abstolerance = 0.05
$ansprompt = "x = "

That is the whole mechanism. Each type's page lists the options that matter for it; a few, such as $hints, are read for every type.

The worked examples on the type pages show Common Control in two parts — setup, then answer and options — only to make them easier to read. Both parts go in the one Common Control box, setup first.

The types

Each type's page gives its exact type name, the options it reads, and a worked example.

Type name Page Student enters
number Number an integer or decimal number (not an expression like 2/3 — use calculated)
calculated Calculated an expression checked by evaluation
choices Multiple Choice one option from a list
multans Multiple Answer several options from a list
matching Matching pairings between two lists
numfunc Function a function expression, compared over a domain
string String short text
essay Essay long-form writing
draw Drawing a sketch on a canvas
matrix Matrices a grid of entries
complex Complex Numbers a complex number
ntuple N-Tuple an ordered tuple or point
interval Intervals interval notation
chemeqn Chemistry a chemical equation
file File Upload an uploaded file
conditional Conditional anything — you write the grader

numfunc is typed, not drawn

The Function type takes a typed formula and compares it against the correct one across a domain — it is not a graphing input. Earlier versions of this page described it as "graph drawing"; that is Drawing.

Types without their own page

These variants have no page of their own; each is covered in a section of its base type's page — Matrices, N-Tuple, Complex Numbers, Intervals, and Chemistry for molecule:

calccomplex, calcinterval, calcmatrix, calcntuple, calccomplexmatrix, calccomplexntuple, algmatrix, algntuple, complexmatrix, complexntuple, molecule

The calc* family accepts an expression where the plain type accepts a value — calcmatrix grades a matrix of expressions where matrix grades numbers. The alg* family accepts entries containing variables and compares each one like Function does — by evaluating it at random test points — so these types also read $variables and $domain. Variants can read options their base type does not (for example calcmatrix also reads $hidepreview), so check the variant's section on the base type's page.

Options shared across types

Most types read some of these. Each page lists the ones that apply to it.

Variable Effect
$answer the correct answer (multans and draw use $answers, matching pairs $questions with $answers by position ($matchlist can override); essay and file need none)
$ansprompt text shown immediately before the input box
$answerboxsize width of the input box
$answerformat accepted answer formats
$displayformat how the answer entry is laid out (e.g. horiz or select for choices)
$reqdecimals n decimal places: with no tolerance set it grades to ±0.5×10⁻ⁿ; with $abstolerance or $reltolerance set it does not affect grading; for number only, write "=n" to require exactly n decimals (other types read "=n" as n)
$reqsigfigs significant figures required
$abstolerance / $reltolerance grading tolerance, absolute or relative
$scoremethod how partial credit is apportioned
$partialcredit extra answers worth partial credit, as answer/credit pairs, e.g. array(-5, 0.5) (for choices, the answer is an option index)
$requiretimes require or forbid symbols in the student's entry, as symbol/count pairs — e.g. "^,=0" rejects any entry using ^
$hidepreview hide the live preview of what the student typed
$noshuffle keep listed options in the order given
$hints, $hintlabel per-attempt hints

Choosing a type

If the answer is Use
a number, possibly with units or precision rules number
an expression that must evaluate correctly calculated
one or several items from a fixed list choices, multans
a formula in one or more variables numfunc
a point, vector or ordered pair ntuple
a domain, range or solution set interval
a matrix matrix
free writing, or work to be marked by hand essay, file
gradeable only by logic you write conditional

See Also