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
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.
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 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 as a number.
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 random module of Python 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 that specific 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. 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.
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.