By the use of some HTML-code, the range of question types that can take advantage of parameterisation can be extended.
How to parameterise a multiple-choice question
Within all exercises in Ans, Python code can be used to create variables in the code editor. Within the question fields of these exercises, the variable dropdown can be selected to choose a variable to add into the content of the question. For some question types, these variables can also be used to create variables in the answer options.
In the table below, you can see the fields in which different question types support the use of variables.
|Question type||Question field||Answer field|
|Open question||Yes||Not applicable|
|Numerical question||Yes||Yes (the variable can be used as answer)|
|Mathematical question||Yes||Not applicable|
|Multiple choice||Yes||Yes (the variable can be used as answer alternative)|
|Code editor||Yes||Not applicable|
|Fill-in question||Yes||Yes (variables can be inserted in the answer field, but not used as answers themselves)|
|File upload||Yes||Not applicable|
|Hotspot match||Yes||Not applicable|
Below is a simple script to generate a correct and a incorrect answer. You could, for example, modify this so that the correct response is the correct calculation of a parameterised variable and the distractors are based on the incorrect application of a formula to that variable. Each student could see a different combination of correct responses and distractors.
Step 1. Add the following code to the code editor
- Click New exercise and fill in a title.
- Click more_horiz-icon and select Code editor. A new dialogue will open.
- You can write your code in the black input field. Fill in the answer as the Correct_Response variable and fill in the wrong answer options in the All_Distractors list.
- Click Run and the code will be tested.
- Click Save.
Step 2. Add the answer options
- Click New question and select Multiple choice.
- Fill in the question and click Add alternative.
- Click the create-icon at the right and a text-field will pop up.
- Click the <>-icon and you can write code to refer to the declared variable.
- Click Save and a blue box with the name of the variable will be added.
The resulting question can be seen below. The multiple choice option answers are randomly assigned based on the distractor answers defined in the code editor. The correct answer will always be present as this has been added to a separate multiple choice alternative.
Parameterising numerical questions
Step 1. Define the variables in the code editor
In the following script, random variables are defined which are then used in an equation resulting in the answer variable. These 4 variables will be used in the question, ensuring that every participant receives a different question that is still graded automatically.
Step 2. Add the variables to the question content
Define the question by adding the variables to the question content. Use the variables from the variables dropdown, the same way it was done for the previous example.
Step 3. Set the question to use a variable for an answer
In the settings of the question, check the Use variable checkbox. This will change the way the question editor looks, allowing a variable to be added as answer in the next step.
Step 4. Select the variable as an answer
Now that Use variable has been enabled, the answer can be defined using the Variable dropdown ans selecting the answer that needs to be given.