Number¶
Answer type: number
The student types a number — an integer or a decimal (scientific notation such as 3E6 also works). Expressions are not evaluated: 84/2 or 6*7 is marked wrong. Use Calculated if students may enter an expression.
The minimum¶
Select Number as the question's answer type, then in Common Control:
$answer = 42
The question text goes in the separate Question Text box, not alongside the code:
<p>What is `6 xx 7`?</p>
No [number] section, and options need a $
Earlier versions of this page showed [number] followed by answer = 42;.
There are no bracketed sections, the answer type is chosen in the editor
rather than written in code, and every option is a variable with a dollar
sign. tolerance, type and showpreview are not options at all.
Tolerance¶
If you set neither tolerance, a relative tolerance of 0.0015 applies — roughly 0.15%.
$reltolerance¶
Relative to the size of the answer. Use it for values that vary in magnitude across randomizations.
$answer = 12345.6
$reltolerance = 0.001 // accepts within 0.1%
$abstolerance¶
A fixed window, in the answer's own units. Use it when the acceptable error does not scale — money, or a measurement read off an instrument.
$answer = 3.14159
$abstolerance = 0.01 // accepts 3.13159 to 3.15159
Set one or the other, not both.
Requiring a precision¶
$reqdecimals¶
Sets the accuracy expected. $reqdecimals = n implies an absolute tolerance of 0.5 / 10^n unless you set a tolerance yourself. It does not count the decimal places the student typed, and the window is centred on the unrounded $answer, so a value that rounds differently can still pass. Write it as "=n" to require exactly n decimal places, compared with $answer rounded to n places; with $reqdecimals = "=2" the example below would accept only 2.65.
$answer = 2.6458
$reqdecimals = 2 // accepts anything within 0.005 of 2.6458: 2.65, 2.646, even 2.641
$reqsigfigs¶
The same for significant figures — the option for measurement and science questions.
$answer = 0.0023456
$reqsigfigs = 3 // accepts 0.00235 or 0.002346; rejects 0.0023 (too few) and 0.00234
Display and input¶
$ansprompt¶
Text placed immediately before the input box. It is plain text, not the box's accessible name — screen readers announce the box by its question number plus $readerlabel, so set $readerlabel as well if the prompt matters.
$ansprompt = "x = "
$answerboxsize¶
Width of the input box, in characters. Narrow it for short answers so the box does not imply a longer response.
$answerboxsize = 6
$displayformat¶
A string, not a number. For number questions the useful values are:
| Value | Effect |
|---|---|
"alignright" |
right-align the typed value |
"hidden" |
hide the box — for answers captured some other way |
"credit" / "debit" |
accounting entry behaviour |
"point" / "vector" |
draw ( ) or < > around the box — the student still enters a single number |
$displayformat = "alignright"
$answerformat¶
A comma-separated list of format flags. For number the engine recognises "integer" (reject non-integers such as 3.5), "list", "exactlist" and "orderedlist" (comma-separated lists), "set" / "exactset", "units", "parenneg" (accept (5) for −5) and "nosoln" / "nosolninf". oo and DNE are always accepted without a flag; "decimal" and "degree" do nothing here.
$answerformat = "integer"
$requiretimes¶
A string of comma-separated symbol, count pairs that the typed entry must satisfy; each count starts with =, !=, <, >, <= or >=. For example $requiretimes = ".,=0" rejects any entry containing a decimal point, so 4.0 is marked wrong where 4 is right.
$hidepreview¶
Has no effect on number questions: the Number answer box never shows a live preview (only types such as Calculated do), so there is nothing to hide.
Partial credit¶
$partialcredit gives credit for specific wrong answers, as value/credit pairs: $partialcredit = array(6, 0.5) awards half credit for 6. The pairs are compared with the same tolerance as $answer, but $reqdecimals and $reqsigfigs are not applied to them. $scoremethod does not apportion this credit, and in the current assessment player it has no effect on a single Number question — even "allornothing" leaves the partial credit in place.
Examples¶
A sum with randomized values¶
Common Control — setup:
$num1 = rand(5, 10)
$num2 = rand(3, 8)
$total = $num1 + $num2
Question Text:
<p>What is `$num1 + $num2`?</p>
Common Control, continued — answer and options:
$answer = $total
$abstolerance = 0
A percentage, to one decimal place¶
Common Control — setup:
$total = rand(150, 400)
$absent = rand(10, 60)
$pct = 100 * $absent / $total
Question Text:
<p>A class has $total students and $absent are absent.
What percentage is absent? Give your answer to one decimal place, without a % sign.</p>
Common Control, continued — answer and options:
$answer = $pct
$reqdecimals = 1
$ansprompt = "% absent: "
A decimal approximation¶
Common Control — setup:
$n = randfrom(array(5, 7, 10, 13))
$root = sqrt($n)
Question Text:
<p>Approximate `sqrt($n)` to two decimal places.</p>
Common Control, continued — answer and options:
$answer = $root
$reqdecimals = 2
How grading works¶
The student's entry is not evaluated: $, spaces, /, ^, * and thousands-separator commas are removed (so 3/4 is read as 34; any other comma makes the entry wrong) and what remains must be a plain number. It is then compared against $answer:
- within
$abstolerance, if set; or - within
$reltolerance× the answer's magnitude; or - within the default relative tolerance of 0.0015.
$reqdecimals does not count the decimal places typed unless written with = (for example "=2"); otherwise it acts only through its implied tolerance. $reqsigfigs replaces the tolerance check: the entry must have at least that many significant figures (exactly that many with =) and must equal $answer rounded to the significant figures the student gave. $abstolerance and $reltolerance are then ignored.
See Also¶
- Calculated — when students may type a calculation such as
3/4orsqrt(2); for an answer inx, use Function - Complex Numbers — complex answers
- Common Options — hints, feedback, display options shared by every type
- Format Macros —
prettysigfigand friends, for showing values in the question text