Variables can be used to substitute question texts, define answers and specify grading criteria. One of the main goals of the system of variables is to simplify the task of making variations of questions. Since the variables are generated at the beginning of a quiz, the quiz will be stopped if errors occur. Thus, in order to minimize errors, the system is designed to have only deterministic variables, lists of constant length and no branching.
There are four types of variables (random, global, local and grading) which you can define and manipulate in the following fields:
Field | Scope of application |
Random variables | The place to define the variation of the variables for the whole question. |
Global variables | The scope includes all random variables (instantiated). |
Local variables | The scope includes all global variables. Note: Each Part has its own scope of local variables. |
Grading variables | The scope includes all local variables, plus special variables (e.g. _0, _1) depending on students' response. |
In addition, you can use the four types of variables in the following fields:
Field | Scope of application |
Question text | All global variables can be used in substitution. |
Part's text | All local variables for the Part can be used in substitution. |
Answer | All local variables for the part can be used in the expression. |
Grading criteria | All grading variables can be used in the expression. |
A variable name is a string of alphanumeric characters (a-z, A-Z, 0-9 and _) that cannot begin with a number or the underscore. Examples of valid variable names are: x, y1, z_1, foo_bar, myFirstVariable.
Variable names are case-sensitive so that, for example, the following names indicate four different variables: foobar, FooBar, fooBar, FOOBAR.
Each variable will be implicitly assigned with a type. The type is either number, string or algebraic variable, or list of numbers or list of strings. A list is defined as elements enclosed by [ and ]. An element in a list can be referred to using the syntax A[b], for example [4,5,6][0] gives the first number, that is, 4. These types are listed below:
Type | Description |
Number | A number, for example 1.2e-3. |
String | Characters enclosed by two double quotes, for example "Hello". |
List of numbers | Numbers enclosed by [ and ], for example [4,5,6]. The equivalent short syntax is [4:7] or [4:7:1]. |
List of strings | Strings enclosed by [ and ], for example ["A","B","C"]. |
Algebraic variable | Set of numbers defined in the non-random variables scopes, for example {1:100}. |
When the quiz is created, one value defined by the expression is assigned to each random variable. As a result, each student can have his own set of values for a quiz attempt.
A random variable has a different syntax from other variables and is set only in the Random variables field. These variables can be defined by assigning a set of elements or by shuffling a list. The probability of selecting each element is equal, so that each element has the same chance of being drawn. There are three types of expressions:
A set of elements consists of elements delimited by { and }. Elements can be numbers, strings, lists of numbers, or lists of strings. For example, the variable F below is a set of list of numbers, and the probability for the element [2,4] is 1/5:
F = {[0,0], [1,1], [2,4], [3,9], [4,16]};
A set of numbers consists of numbers delimited by { and }. You can also specify a range in the format of {begin:end:interval}, where the numbers satisfying (begin + n*interval) < end, n = 0,1,2,3... will be generated. If the interval is not specified, the value 1 will be used. Note that the end value is not included by definition, but may be included for non-integers due to numerical errors. The sets of numbers defined below illustrate different range syntaxes. The probabilities of the elements in each set are respectively 1/8, 1/10 and 1/20:
A = {1,2,3,4,5,6,7,8}; B = {0:1:0.1}; C = {1:10, 10:100:10, 100, 200};
A list can be passed to the shuffle() function. In the example below, the instantiated variable S will be one of the permutations of the input list, say [4,3,2,5] or [2,5,4,2]. The probability of each list is therefore 1/4! = 1/24:
S = shuffle([2,3,4,5]);
In order to generate several different random values from a set of elements, shuffle the set and select the desired number of values from the shuffled set.
In the example below, the following four lines of settings will generate 3 different random numbers from the set [0,1,2,3,4,5,6].
Variables Random variables shuffledDays=shuffle([0,1,2,3,4,5,6]); Global variables i1=shuffledDays[0]; i2=shuffledDays[1]; i3=shuffledDays[2];
Generate randomly three different days of the week.
The Formulas question should look like this:
Variable assignments allow you to define and manipulate variables. They can be defined in the field of global variables, local variables and grading variables.
Component | Definition |
Expression | Any combination of numbers and variables with the operators and functions listed herein: Typically, it's just a simple mathematical formula evaluated to a number. The variables used in the expression must be defined previously. |
Assignment | Assigns the evaluated result of an expression to a variable, in the form of: name = expression;
|
"for" loop | Allows simple iteration in the form of: for (element:list) assignment;
All elements in the list are iterated. |
Examples of assignments are shown below:
Example | Comment |
a = 1; # comment | The text between # and the end of the line is treated as a comment. |
b = exp(3.333); | |
d = round(b,1); | The function round() rounds a number to the desired decimal. |
e = 1 + sin(2) + pow(a,2); | |
A = [1,2,3]; | |
x = A[0]; | |
y = A[a]; | |
z = A[2]; | |
w = A[0] + A[1] + A[2]; | |
m = max(x, y); | |
distance = sqrt(x*x + y*y + z*z); | |
theta = atan2(y, x); | |
smaller = x < y; |
smaller is 1. |
con = (x < y) + (y < z); |
con is 2. |
B = fill(3,0); | B is now [0,0,0]. |
C = map("sqrt",fill(3,16)); | Square root of [16,16,16], so C is now [4,4,4]. |
s = 0; for (i:A) s = s + i; |
s is 6 after the loop. |
for (i:[0:3]) { B[i] = sum(map("+",A,fill(3,i))); } |
B will be [6,9,12]. |
p = pick(a+9,"","A","B"); | pick() always chooses the first element if the index is out of range. |
u = {-3,-2,-1,1:100}; v = {-100:100:1}; |
u and v define algebraic variables. Numbers are evaluation points. |
© 2019-2024 Dynamic Courseware (Dominique Bauer)
Documentation: CC0 1.0 Universal - No copyright
Remixes for Moodle: CC BY-NC-SA 4.0 Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
Contact request sent
Personal space
Save draft messages, links, notes etc. to access later.
No starred conversations
No group conversations
No private conversations
No results
Search people and messages
You can restrict who can message you
You have blocked this user.
You are unable to message this user