6.16 Working with Variable Data
For each type of question supported, you can include algorithmically generated (random) variables in question statements, answers, hints, and feedback. Using variables in questions, you can generate variations on a single template question.
- Range-based variables: You can specify mathematical ranges (set by declaring minimum and maximum data values and increments for randomly generated data). Range-based variables are defined by a formula, and can include mathematical operations. For example, you can specify a variable x that is a random integer between 0 and 30, in steps of 3, using the variable definition: $x=range(0,30,3). See the tutorial on this topic, Tutorial: Algorithmic Question.
- List-based variables: You can randomly select a set of data from lists, and present to students a scenario with related variables. For example, you can create an astronomy question that randomly selects a planet in our solar system, and then automatically assigns the acceleration due to gravity at the planet's surface to the answer variable. See the tutorial on this topic, Tutorial: List-based Variables.
You can use more than one type of variable in a question. You can use any combination.
You can place conditions on variables. For example, you can specify that the value of a variable not exceed that of another.
See Also:
Generating Random Numbers in Questions
Mathematical and Logical Operators in Algorithms and Answers
The Algorithm Designer
Functions within Algorithms
Algorithmic definitions of variables are of the form:
qu.x.y.algorithm=
$variable1=expression;
$variable2=expression;
@
- The use of the semicolon at the end of the variable definition is optional if there is only one variable defined in the algorithm statement.
- The syntax of formulas and the use of operators in variable definition statements is similar to the standard graphing calculator syntax used in the system, with the addition of some new functions. Therefore, the system's usual arithmetic operations and functions can be used in the expression portion of the code statement.
- However, unlike most other programming languages, variables cannot be redefined in terms of themselves (for example, the statement $a=$a+1; is invalid).
The following additional functions and operations are also available for use in variable definitions in algorithms.
Random integer generation (integers in a specified range, in steps of k):
Random real number generation (to k significant digits):
Inline Variable Expressions
You can include a computed expression anywhere within a question statement, comment, or hint.
- Inline variable expressions can contain computations involving functions or algorithmic variables defined elsewhere in the question.
- The syntax is to enclose the expression in ${...}.
For example, you can include expressions like ${$n + 1} in place of defining a separate variable to hold n+1. This simplifies complex algorithms.
Example
qu.1.1.question=
What is the derivative of x^$n?
@
qu.1.1.answer=
$n x^${$n-1}
@
qu.1.1.algorithm=
$n=range(2,10);
@
See Also:
mathml(f)
Inline Display of Formatted Math Expressions
Simplified Math Expressions
Rules for Naming Variables
Follow these rules when naming variables:
- A variable name must be of the form $name or ${name}.
- The string name can consist of letters (a-z and A-Z), numbers (0-9), and underscore characters (_).
- The first character of name must be an alphabetic character (a-z or A-Z).
- If the ${name} form is used, spaces can also appear in name. This allows you to use multiple word names without the underscore character.
See Also:
Functions within Algorithms