Calculated multiple choice quiz question

Prev Next

Calculated multiple choice questions operate much like the multiple choice question type, however the choices available are generated from a given formula using wildcards and datasets, as with the calculated question type.

For example, a question may be: 'Calculate the area of a rectangle where its width = {width} and its height = {height}.

The correct answer would be: 'The rectangle's area is {={width}*{height}} cm²' 

An incorrect answer could be: 'The rectangle's area is {={width}+{height}} cm²' 

The correct answer choice would display with the calculated answer, based on the values the system automatically generates.

Calculated quiz questions present a potential security risk in that they can be used to execute PHP code on the server, so you may want to limit who is able to add these quiz questions. The ability to add Calculated, Calculated simple and Calculated multiple choice quiz questions is controlled by the moodle/question:managecalculated capability. For upgraded sites this capability will be assigned to any users who already have the moodle/question:add capability. For new sites, this capability is not assigned to any roles by default. In either case, we recommend that Site Administrators review whether calculated quiz questions are required, and limit the capability to administrative roles where possible. No special role is required to use existing calculated questions in a quiz.

A calculated multiple choice quiz question from the Learner's perspective.

To set up a calculated multiple choice quiz question, follow these steps:

  1. In the quiz activity, click Add, then select a new question.
  2. Select Calculated multiple choice, then click Add.
  3. Give the question a name, then enter the question in the Question text field. The question text must include the wildcards you will use in the answer formula, with each one inside a set of curly brackets. For example:
    'A rectangle has a width of {width} and a height of {height}. What is the area of this rectangle?'
  4. Set the Default mark, i.e. how many marks the Learner will be awarded if they answer correctly.
  5. Configure the other General settings as required.
  6. Enter a formula in each of the Choice fields, with at least one answer using the correct formula that will be used to calculated the correct answer based on the wildcards that are randomly generated. For example, entering {={width}*{height}} would mean the correct answer would be calculated by multiplying two wildcards: {height} and {width}. An incorrect choice could include the formula {={width}+{height}*2}. See Answer formula syntax for more information. You can configure additional answers by clicking Blanks for 3 more choices.
  7. Set the grade weighting for each answer.
  8. Add feedback for each choice. If you don't want to provide specific feedback for each answer, either use the General feedback field or the Combined feedback section.
  9. If required, configure the Units and Unit handling sections.
  10. If required, configure the Multiple tries and Tags sections.
  11. Click Save changes.
  12. Set which dataset you wish to use for the wildcards, and set whether data is synchronised with other questions in the quiz.
  13. Click Next page.
  14. Manually add wildcard values by entering values in the Wild card {x} fields, then clicking Add. If you want Totara to generate the values, you can additionally enter the Minimum and Maximum for the Range of values, set the number of decimal places, and select which distribution to use (Uniform means all values in the range are equally likely, while Loguniform means higher values are less likely to be generated). Note that you can generate multiple wildcards at once using the dropdown next to the Add button.
  15. Click Save changes.

Course badgeThere are two courses in the Totara Academy about using quizzes in Totara Learn, Getting started with quizzes and Advanced quiz Using these courses you can learn more on how to use these features, see best practice, and give it a go yourself.


Join the Totara Community for more resources to help you get the most out of Totara. 


© Copyright 2025 Totara Learning Solutions. All rights reserved. Some content originally obtained via GPLv3 license and continues to be available under GPLv3. All other content is the sole copyright of Totara Learning Solutions.