Skip to content
Classroom

Multipart

Multipart is a question type: set the question's type to Multipart in the editor, then declare $anstypes — plural — to give each part its own answer type. Declaring $anstypes in a question of any other type (Conditional aside) does not make it multipart: the engine reports It looks like you have defined $anstypes; did you mean for this question to be Multipart? and discards $anstypes.

The minimum

Common Control:

$anstypes = array("number", "number")
$answer = array(12, 30)

Everything is positional: $anstypes[0] grades $answer[0], and so on. The answers go in $answer, singular. $answers is a different option, read only by the multiple-answer, matching and drawing types; a number part given $answers has no correct answer and marks every typed response wrong.

Missing $anstypes fails the question

A question that needs $anstypes and does not have it shows authors Error in question: missing $anstypes for multipart or conditional question and displays a single number box. Grading does not fall back: the scorer finds no parts, so the box is never graded.

$anstypes also accepts a comma-separated string, which the engine splits and trims:

$anstypes = "number,string"

Mixing types

Parts do not have to match. A worked problem can ask for a value, an expression and an explanation in one question:

$anstypes = array("number", "numfunc", "essay")

Per-part options

Any option that a part's type reads can be given as an array, one entry per part. A scalar applies to every part.

$anstypes = array("number", "number")
$answer = array(3.14159, 2.71828)
$reqdecimals = array(2, 3)          // different precision per part
$answerboxsize = 8                  // the same box width for both

One exception: a scalar $abstolerance does not survive a per-part $reqdecimals array. The engine replaces it, part by part, with the tolerance that part's $reqdecimals implies — half a unit in the last requested place, 0.005 and 0.0005 here. To set your own tolerance alongside a per-part $reqdecimals, give $abstolerance as an array too.

Placing the answer boxes

By default the parts appear in order after the question text. To put them inline — inside a sentence or a table — reference them by index in qtext. The index starts at zero, so the first part is [AB0]:

<p>The vertex is ( [AB0] , [AB1] ).</p>

Place every box or none. Once you place any of them, the engine adds none of the others below the question, so a part you leave out has no box at all, and testing gives no warning.

Weighting

$answeights sets the share of the question's points each part carries. Left unset, the engine divides the points evenly across the parts. Set it when the parts differ in difficulty — an even split between a one-step arithmetic part and a full derivation misrepresents both.

$answeights = array(1, 3)

Feedback per part

Only getfeedbackbasic($correct, $wrong, $thisq, $partn) takes a part index. The getfeedbacktxt* macros take the student's answer as their first argument, so pass that part's entry — $stuanswers[$thisq][1] for the second part. See Feedback Macros.

Example

Common Control — setup:

$h = rand(-6, 6)
$k = rand(-6, 6)
$a = nonzerorand(-3, 3)
$eq = makexxpretty("$a(x - $h)^2 + $k")

Question Text:

<p>For `y = $eq`:</p>
<p>Vertex: ( [AB0] , [AB1] )</p>
<p>Does it open upward or downward? [AB2]</p>

Common Control, continued — answer and options:

$anstypes = array("number", "number", "choices")
$answer = array($h, $k, ifthen($a > 0, 0, 1))
$questions = array("", "", array("upward", "downward"))
$answeights = array(2, 2, 1)

See Also