To take the quizzes, you must log in.

*Username:***student***Password:***Formulas.1**You can view this site in

the language of your choice.

- Variables
### Variables

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.

## Scope of variables

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. ## Name of variables

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.

## Types of variables

Each variable will be implicitly assigned with a type. The type is either

*number*,*string**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}. ## Random variables

When the quiz is created,

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.*one*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:- Set of elements
- Set of numbers
- Shuffled list

### Set of elements

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]};`

### Set of numbers

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};

### Shuffled list

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]);`

### Several different random variables from a set

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];

### Example

Generate randomly three different days of the week.

## Question settings

The Formulas question should look like this:

## Variable assignments

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. ## Notes

**Important!**Index out of range can not be verified by validation when the question is saved, so you must verify it yourself. Otherwise, initialization of the quiz for some students may fail. Use pick() as a safe alternative, if necessary.

- Logical "true" is treated as 1 and "false" as 0, so the variable con above gets the value 2.

- Variable assignments do not include branching. However, you can use the ternary operator (condition)?(true):(false) for numbers. For the general case, e.g. for strings, you can use the pick() function.

- The available functions are listed in the section on functions. There are many other functions for numeric list operations and some for string list operations.