The code editor is used to create changing parameters for questions in tests. This way students cannot copy another student's answer if something has to be calculated. The code editor can also be used to calculate difficult functions.
How it works
When creating a test, questions have to be written. These questions can contain numbers or parameters when the students have to do a calculation. To make these numbers change of value for each student, the code editor can be used. In the code editor variables can be created, which later can be used in the question and in the criteria of the question. These variables can be used in the content of a question as well as a subquestion. Also, in the code editor the answer to each question needs to be calculated using the variables, so these variables can be used in the criteria. A variable can be added up by +, subtracted by -, divided by /, multiplied by * and be done to the power of by **. Make sure to use brackets if needed.
How to use the code editor
- Create an assignment. Read here on how to create an assignment.
- Click New exercise and fill in a title.
- Click more_horiz-icon and select Script editor. A modal will open.
- You can write your code in the black input field.
- Click Run and the code will be tested.
- Click Save.
How to use the created variables in content, questions and criteria
- Click Variable in the menu of the description box and select the variable.
- The variable will be shown in a blue box with the name as it was given in the code editor. This way it will be visible in the test as a number.
Example 1: How to use unique variables per student
To create a variable with a changing value per student, the function random(x,y,step=z) can be used. This function will have a value somewhere between x and y and will have steps of z. This means that when the function has a value between 1 and 4 with steps of 1, the variable can have the values 1, 2, 3 and 4.
Example 2: How to calculate an answer with a function
To create difficult functions, python libraries can be used. With the math library, sinus functions and logarithmic functions can be calculated for example. You can import a new library by using the code: import #library_name.
Example 3: How to calculate an answer with a function (II)
To create an integral for example, python libraries can be used. With the import scipy.integrate library, integrals can be calculated. You can import a new library by using the code: import #library_name. See the image below for an example.
In the example, the integral values are calculated by the code: integrate.quad(lambda x: x**2, 1, 4)
- lambda x: defines the variable x
- x**2: defines the function that has to be integrated
- 1: lower bound
- 4: upper bound
The absolute (abs()) difference can be taken to get to the final answers. The round() function will round off the answer.
- A student will receive the same value within a test (or attempt) if a random function is used several times within the test. This means, that w = random(x, y, z) will give the same value for a different w when x, y, z are the same.
- The random module of Python can not be used in Ans. This is due to technical issues that could occur. Instead of making use of that specific module, make use of the random function as explained above.
lightbulb_outline When you want to make use of the random function twice on the same domain, you can make use of the following example:
a = random(1,10,1)
b = random(2,11,1)-1
Using the code editor is necessary for a numerical question. Find out how to create a numerical question here.