Note: You are currently viewing documentation for Moodle 2.9. Up-to-date documentation for the latest stable version of Moodle may be available here: question/type/stack/doc/doc.php/Authoring/KeyVals.md.

question/type/stack/doc/doc.php/Authoring/KeyVals.md

From MoodleDocs

STACK Question Variables

This field is for variables that are used later in the question. The values can be quite general: integers, floating point numbers, symbols or expressions, or random selections of any of the preceding elements. The variables can be access in other fields of the question by including them in CAStext. The assignment operator is the colon (:), as is consistent with the maxima program which processes expressions in STACK. These assignments can be used to build up complicated expressions from simple ones using maxima syntax.

Simple Assignments

An example of a simple variable assignment is

p:5;

This assigns the value of 5 to the variable p. In your question text, but example the appearance of @p@, will be replaced by 5. The line need not end in a semicolon, but its good practice in case you want to cut and past the assignments into a maxima session for testing.

q:x^2+2;

This assigns the symbolic expression representing 'x2+2' to the variable q. This can be used as a model answer, for instance or part or a later expression.

Random Assignments

The significant power of question variables becomes evident when they are used to generate randomly chosen values for a question by means of the rand operator.