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. In the code editor, you can use Python to create variables.
How it works
It is possible to create questions that include numbers or parameters for which students need to perform calculations. To allow these numbers to vary for each student, the code editor can be used. In the code editor, variables can be created that can later be used in the question content and in the evaluation of the question. These variables can be used in the content of an exercise or a question. 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.
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 Code editor. A modal window will open.
- You can write your code in the black input field.
- Click Run and the code will be tested.
- Click Save.
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.
Example 1: 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.
The Python Random module cannot be used in Ans. This is to ensure that any random numbers seen while grading match the numbers that the student saw while taking the test. Instead of making use of the Python random module, make use of the random function as explained above.
Example 2: Calculate an answer with a function
To create difficult functions, python libraries can be used. With the math library, sine functions and logarithmic functions can be calculated for example. You can import a new library by using the code: import #library_name.
Example 3: 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.
Below is a list of the supported Python libraries including the installed version of those packages. These packages can be imported and used in the code editor:
- CoolProp version 6.4.1
- SciPy version 1.7.3
- SymPy version 1.7.1
- NumPy version 1.21.5
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 receive to the final answers. The round() function will round off the answer.
What’s next
Using the code editor is necessary for a numerical question. Find out how to create a numerical question here.
Comments
0 comments
Please sign in to leave a comment.