Embedded Answers (Cloze) question type

From MoodleDocs
(Redirected from Cloze)


Embedded answers (Cloze) questions consist of a passage of text (in Moodle format) that has various answers embedded within it, including multiple choice, short answers and numerical answers.

Until mid2013, there was no graphical interface to create these questions within your Moodle site - you needed to specify the question format using the text box or by importing them from external files.

There is an Excel-based Moodle Cloze and GIFT Generator that was presented at the 2017 and 2019 Moodle Moot Japan and updated extensively in 2022.

=Cloze Editor version for TinyMCE

The Cloze editor for the new TinyMCE editor (worked on during MoodlemootDACH 2023) is available for Moodle 4.1 and later at https://moodle.org/plugins/tiny_cloze

Lots of people suggested that Hot Potatoes software is the easiest way to create Embedded answer (Cloze) questions. Once you have created your questions on your PC, you can then import them into Moodle's quiz module. However, the flexibility of the Cloze question type is hard to equal and despite the minor coding that you need to create the questions, it has great worth in the Moodle Quiz.

Question set-up

  1. Select the question category
  2. Give the question a descriptive name - this allows you to identify it in the question bank.
  3. Enter the passage of text (in Moodle format - see Format below) into the 'question text' field.
  4. Select an image to display if you want to add a picture to the question. For the student, it appears immediately above the question text.
  5. Set the 'default question grade' (i.e. the maximum number of marks for this question).
  6. Set the 'Penalty factor' (see Penalty factor below).
  7. If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.
  8. The editor has been modified and allows you to test if your syntax is good. The different questions elements decoded will be displayed and syntax errors pinpoint. However, it cannot check if the question decoded is two questions in one because of an error syntax (for example ~}, =~, etc.).
  9. Click Save changes to add the question to the category.

Penalty factor

The 'penalty factor' only applies when the question is used in a quiz using adaptive mode - i.e. where the student is allowed multiple attempts at a question even within the same attempt at the quiz. If the penalty factor is more than 0, then the student will lose that proportion of the maximum grade upon each successive attempt. For example, if the default question grade is 10, and the penalty factor is 0.2, then each successive attempt after the first one will incur a penalty of 0.2 x 10 = 2 points. The grading for the cloze question applies the penalty to each subpart of the question as a whole. For example, if you have three fill in the blanks each worth 1 point each, then the penalty will only be incurred on the incorrect parts, not the questions as a whole.

Question rendering

The question answer entry space or INPUT HTML ELEMENT (for Short Answer and Numerical question types) and the dropdown list or SELECT HTML ELEMENT (for multichoice) are normally displayed in-line with the text.

The size of the entry space or INPUT HTML ELEMENT ( Short and Numerical) will be adjustable to the length of the longest answer (good or bad) + a random number (0 to 15% total length).(Pierre Pichet 15:37, 26 January 2008 (CST))

The size will adjust to the length of the student response when displayed in the grading and feedback process.

The size of the dropdown list or SELECT HTML ELEMENT (multichoice) adjusts itself automatically to the longest answer.

Format

Questions consist of a passage of text (in Moodle format) that has various sub-questions embedded within it, including

  • short answers (SHORTANSWER or SA or MW), case is unimportant,
  • short answers (SHORTANSWER_C or SAC or MWC), case must match,
  • numerical answers (NUMERICAL or NM),
  • multiple choice (MULTICHOICE or MC), represented as a dropdown menu in-line in the text,
  • multiple choice (MULTICHOICE_V or MCV), represented as a vertical column of radio buttons, or
  • multiple choice (MULTICHOICE_H or MCH), represented as a horizontal row of radio-buttons,
  • multiple choice (MULTIRESPONSE or MR), represented as a vertical row of checkboxes
  • multiple choice (MULTIRESPONSE_H or MRH), represented as a horizontal row of checkboxes

Shuffle sub questions

When the quiz question behavior shuffle option is set to YES, the following special multiple choice sub-questions elements will be shuffled:

  • multiple choice (MULTICHOICE_S or MCS), represented as a dropdown menu in-line in the text,
  • multiple choice (MULTICHOICE_VS or MCVS), represented as a vertical column of radio buttons, or
  • multiple choice (MULTICHOICE_HS or MCHS), represented as a horizontal row of radio-buttons.
  • multiple choice (MULTIRESPONSE_S or MRS), represented as a vertical row of checkboxes
  • multiple choice (MULTIRESPONSE_HS or MRHS), represented as a horizontal row of checkboxes
Note: MCS, MCVS, MCHS are new (Moodle 3.0) Cloze subquestion types with shuffling of answers. See MDL-38214.

The structure of each cloze sub-question is identical:

{ start the cloze sub-question with a bracket (AltGr+7)
1 define a grade for each cloze by a number (optional). This used for calculation of question grading. Note that this number can only be a positive integer (1, 2, 3, etc.)
:SHORTANSWER: define the type of cloze sub-question. Definition is bounded by ':'.
~ is a separator between answer options
= marks a correct answer
# marks the beginning of an (optional) feedback message
} close the cloze sub-question at the end with a bracket (AltGr+0)

Now a very simple example:

{1:SHORTANSWER:=Berlin} is the capital of Germany.

For full details of the format for embedded-answers questions, see the detailed syntax explanation below.

NB: Be careful when copying a cloze type question into the WYSIWYG HTML editor, as line breaks tend to get added, which destroys the question.

If the correct answer contains } # ~ / " or \ you will have to escape them by putting a \ in front of each such character. But this is tricky. The { shouldn't be escaped, this can be vital in getting TeX expressions to work. In the feedback ~ and } must be escaped otherwise it will be interpreted as the next answer or end of the short answer section respectively. Quotation signs: " can lead to trouble anyhow in both places. Use the HTML entity: & quot; (without the space between & and quot;). If you want to have Mathematical symbols there can be problems with the \ used in TeX expressions. One alternative can be to use unicode characters.

See the notes further down about numerical embedded question!

Examples

Example 1

The following text creates a simple embedded-answers question:

Match the following cities with the correct state:
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}
The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!
~%50%Marseille#No, that is the second largest city in France (after
Paris).~*#Wrong answer. The capital of France is Paris, of course.}.

And the result will be:

Cloze question type

Example 2

This question consists of some text with an answer embedded right here {1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another wrong answer#Feedback for the other wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer}

and right after that you will have to deal with this short answer {1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer}

and finally we have a floating point number {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of the correct answer}.

The multichoice question can also be shown in the vertical display of the standard moodle multiple choice. {2:MCV:1. Wrong answer#Feedback for this wrong answer~2. Another wrong answer#Feedback for the other wrong answer~=3. Correct answer#Feedback for correct answer~%50%4. Answer that gives half the credit#Feedback for half credit answer}

Or in an horizontal display that is included here in a table {2:MCH:a. Wrong answer#Feedback for this wrong answer~b. Another wrong answer#Feedback for the other wrong answer~=c. Correct answer#Feedback for correct answer~%50%d. Answer that gives half the credit#Feedback for half credit answer}

A shortanswer question where case must match. Write moodle in upper case letters {1:SHORTANSWER_C:moodle#Feedback for moodle in lower case ~=MOODLE#Feedback for MOODLE in upper case ~%50%Moodle#Feedback for only first letter in upper case}

Note that addresses like www.moodle.org and smileys :-) all work as normal:

a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}

b) What grade would you give it? {3:NUMERICAL:=3:2}

Cloze example.png

Some things to note:

  • The individual embedded answers are represented by the code in braces {}.
  • The number at the start is the 'weight', so in this case each answer contributes an equal share of the overall grade.
  • The correct option in each case is preceded either by an = sign or by %100%.
  • The text appearing after the # that follows each option is the feedback that the student will see if they choose that option.
  • If the student enters 'Marseille' in the final example, they score 50% of the total grade.
  • The asterisk * preceding the "Wrong answer" feedback in the final example means that the student will see this feedback if they enter anything other than "Paris" or "Marseille".
  • For multiple choice vertical or horizontal rendering there is no automatic numbering, though can added at each answer.

Detailed syntax explanations

  1. All question items within a cloze-type question are coded inside curled braces { }.
  2. The number which appears between the opening brace and the colon {1: is the weighting of that item; if it is set at 1 for all the items, it needs not be specified, so you can have {:.
  3. After the colon we have the item question type: MULTICHOICE, SHORTANSWER, NUMERICAL.
  4. NOTE.- If you have installed the REGEXP question type plugin you can also use the REGEXP question type; see instructions here.
  5. The syntax for MULTICHOICE and SHORTANSWER is the same; the only difference is in the displaying of the item to the student.
  6. The order of the various answers is indifferent (except if you want a catch-all for wrong answers, see #13 below).
  7. A correct answer is preceded with the equal sign = or a percentage (usually %100%) - Note: The equal sign (=) doesn't seem to work with SHORTANSWER.
  8. A wrong answer is preceded with nothing or a percentage (usually %0%)but you can even use negative points by preceding with ~%-25% [not before Moodle 2.0]). Note that negative points are taken into account in all question behaviours except "Interactive with multiple tries".
  9. You can allocate some points between 0 and 100 to some answers, if you put the appropriate percentage.
  10. All answers except the first one are separated from one another by the tilde ~ sign.
  11. Answers can be followed by an optional feedback message, preceded with the # sign; if there is no feedback message, the # sign can be present or absent, it does not matter.
  12. Note that the feedback message and the correct answer are displayed in a small popup window (if and when the correct and or feedback have been declared accessible to the students in the Quiz settings) upon clicking on the feedback icon (green checkmark or red cross). The popup window has a title "feedback" and you can use HTML tags to format your feedback. In some browsers (For example IE5.5) the form fields can cover part of the feedback windows. It can help to not have the formfields for the answers too close to each other.
  13. In the SHORTANSWER type you may want to put a catch-all (wrong) answer in order to send a "wrong, try again" feedback; you can do this by inserting an asterisk * as the very last expected answer in your formula.
  14. You should not have sequences such as %#, %~, %}, =#, =%, =}, ~#, ~% and ~} in the answer because you should not have empty answers or empty answer options. These two character sequences constitute error syntaxes, where the second character is interpreted as if it were escaped(why?), and gives unexpected results: the answer is decoded as one instead of two or more.

Feedback

Note that in MULTICHOICE and MULTICHOICE_V, feedback is displayed when you click on the green checkmark icon for a correct answer or the red cross icon for an incorrect answer (this is different from previous Moodle versions where you had to hover over the answer box). For example:

Question text

Which animal eats mice? (answer: the cat)
Testing MULTICHOICE {1:MULTICHOICE:=the cat#Yes, that's right~the dog#Nope!}
Testing MULTICHOICE_H {1:MULTICHOICE_H:=the cat#Yes, that's right~the dog#Nope!}
Testing MULTICHOICE_V{1:MULTICHOICE:=the cat#Yes, that's right~the dog#Nope!}

Result

Direct and clicking feedback

Images in multichoice questions

You can place images in choices of multiple choice sub-questions with radio buttons or checkboxes, i.e.:

  • MULTICHOICE_V or MCV
  • MULTICHOICE_H or MCH
  • MULTIRESPONSE or MR
  • MULTIRESPONSE_H or MRH

and their shuffled version:

  • MULTICHOICE_VS or MCVS
  • MULTICHOICE_HS or MCHS
  • MULTIRESPONSE_S or MRS
  • MULTIRESPONSE_HS or MRHS


However, you cannot place images in choices of multiple choice sub-questions with a dropdown menu (MULTICHOICE or MC, and MULTICHOICE_S or MCS). (The reason is that these sub-questions rely on the <option>

tag for input and there is no way to pass code with this tag because its permitted content is only "text, possibly with escaped characters"MDM Web docs.)



It is important that the source of the images is a fixed URL. To place images in the choices, edit the HTML code of the question and insert manually <img>

tags with the URL from the images in the Folder. In the example below, the HTML code of the question text contains the following:


Note: For better readability, the following text has been divided into small paragraphs. However, in reality, for the question to work, the text should only be one paragraph.
The first Moodle Research conference was held in

{1:MCV:&nbsp; <img src="https://moodleformulas.org/pluginfile.php/11393/mod_folder/content/0/Public%20domain%20-%20Tunisia%20-%20200x114.jpg">&nbsp; Sousse, Tunisia &nbsp;
#That was the second 

~&nbsp; <img src="https://moodleformulas.org/pluginfile.php/11393/mod_folder/content/0/Public%20domain%20-%20California%20-%20200x114.jpg">&nbsp; California, USA &nbsp;
#That was the third

~=&nbsp; <img src="https://moodleformulas.org/pluginfile.php/11393/mod_folder/content/0/Public%20domain%20-%20Crete%20-%20200x114.jpg">&nbsp; Crete, Greece &nbsp;
#Correct!

~%50%&nbsp; <img src="https://moodleformulas.org/pluginfile.php/11393/mod_folder/content/0/Public%20domain%20-%20Greece%20-%20200x114.jpg">&nbsp; Greece &nbsp;
#Yes but not close enough so you only get half the credit.}


In this example, the original images were already sized to the desired dimensions (200px width). If you want to change the size of the images here, just add the width

attribute. Note that for proportional resizing, you don't need to specify the Template:inlinecodeheight attribute. For example, to proportionally reduce the size of the first image to a width of 150 pixels, write:


<img src="https://moodleformulas.org/pluginfile.php/11393/mod_folder/content/0/Public%20domain%20-%20Tunisia%20-%20200x114.jpg" width="150px">

You will find the following example at Images in mutltichoice questions (use the default student login) where you can try the question and download it in Moodle XML format:

MoodleDocs 20210410 2137.png

Equations in multichoice questions

The MULTICHOICE (MC) sub-question, as well as the MULTICHOICE_S (MCS) sub-question, of the Cloze question type rely on the <option> tag for input. There is no way to pass code with this tag because its permitted content is only "text, possibly with escaped characters"MDM Web docs. In other words, you cannot have equations with the MC or MCS questions.

However, you can have equations in the MULTICHOICE_V (MVC) and MULTICHOICE_H (MCH) sub-questions, as well as in the MULTICHOICE_VS (MCVS) and MULTICHOICE_HS (MCHS) sub-questions. You can use LaTeX, MathML or AsciiMath.

You can also have equations in the feedback of MCV, MCH, MCVS and MCHS questions.


If you are using LaTeX, you must replace {

with its HTML entity reference &#123;
and }
with &#125;

. Also, most of the time, you will want to use \(

and \)
as delimiters for display within text, not on its own line with \[
and \]
and not the older delimiters $$
and $$

.


Dropdown choice titles

In the MULTICHOICE (MC) and MULTICHOICE_S (MCS) sub-questions, it is possible to add information to each choice, in the form of a mouse-over tooltip, using a small JavaScript code.

This can be useful to limit the width of the drop-down menu, for example as mentioned in this thread.


MoodleDocs 20210518 0038.png


You can try the question and download it in Moodle XML format by clicking the button below. Use the default student login.

Try it Yourself

Numerical Cloze questions

From the student perspective, a numerical Cloze question looks just like a short-answer question or fill in the blanks.

The difference is that numerical answers are allowed to have an accepted error. This allows a continuous range of answers to be set. You can also express your answer in some different numerical formats. 23.4 23,4 (some countries use , as a decimal separator) and 2.34E+1 (meaning 2.34*10^1) would be interpreted as the same.

False positives

Note: the following examples of false positives do not apply to Moodle 1.8+, where you cannot use percentages or fractions as the answers in a numerical Cloze test; Moodle will generate an error if you try to save such a question. However the following may be relevant for earlier versions of Moodle.

More examples:	 
0.5 accepts .5 0.5 ,5 0,5 0.500 5e-1 5E-1 but not 1/2 50% 	 
50% accepts 50% 50.0% 5E1% 50/100 even 50/1000 50 but not 500/1000 0.5	 
1/2 accepts 1/2 1/3 1twenty but not 2/4 0.5 0,5 3/6 50% ½	 
½ accepts ½	 
HALF doesn't even accept HALF (maybe 0?)	 

If you want to accept several variants you can have them in the same {} but be careful, notice the "false positives" in bold!

Syntax for numerical Cloze questions

The format of a NUMERICAL Cloze question is similar to that of the other Cloze types and they can be mixed in the same question. As with other Cloze tests, you write your question or incomplete text, and add the Cloze code at the point where the student is supposed to enter their numerical answer.

An example of the syntax used is shown below:

Note: It is preferable to write the code in 'source code' mode. The WSIWYG editor can insert linebreaks that make the question not function. The linebreak in the example box below is for readability only! A problem with these questions is the readability of the code! :(

{2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8	 
~%50%23.8:2#Feedback for ½credit near correct answer}. 	 

In this example:

  • 2: is the question point weight, which means that this question has twice the weight in the final point(s) for this question as other partial answers with weight 1 (or no declared weight - you can start with {: for the default weight 1) in the same question.
  • NUMERICAL: says what kind of question it is. It must be in CAPS.
  • =23.8:0.1 = or %100% means correct if the answer is 23.8 with an accepted error of 0.1, then any number between 23.7 and 23.9 will be accepted as correct. (In the GIFT numerical question one can express an interval like this 13..15 or 14:1 but in Cloze only 14:1 works.)
  • #Feedback for correct answer 23.8 is preceded by #
  • ~%50%23.8:2 ~ is the separator for answer alternatives %50% means this answer would get 50% of the score that the more precise answer had gotten. Because the tolerance here is 2, 21.8 to 25.8 would get this point and feedback.

The feedback (which is seen within a popup window when the user hovers over the answer space) is formattable with HTML tags. For example, if you want an exponent, surround it with superscript tags: <sup> </sup>. You can even include pictures in the feedback popup, but you must clean out all " characters and save while still in source code mode (not WYSIWYG). So, this works in feedback popup:

#See this picture:<br><img src=Something.gif />}	 

but not this:

#See this picture:<br><img src="Something.gif" />}	 

(ALGEBRA and TEX filters don't work in the feedback popups, but they can be very useful in the question writing for math/science expressions). But you can use Unicode characters.

If you want to give feedback for any answer that didn't fit the intervals you already have specified feedback for, add some BIG general intervals, like for positive answers (if they aren't bigger than 20000 you could add:

~%0%10000.0001:10000#Feedback for unspecified not_right answers}	 

This would give feedback for anything from 0.0001 to 20000.0001 (that hadn't already gotten feedback). I didn't want to include 0 since that special case as well as negative ought to have specific reactions.

~%0%0#Hey! It can't be zero	 
~%0%-10000.0001:10000#We just want the size here,	 
so a negative value is not what we want}			 

Numerical questions could, before version 1.7, also have case-insensitive non-numerical answers. This is useful whenever the answer for a numerical question is something like +inf, -inf, NaN etc.

All or nothing

There are two ways to get the "all or nothing" behavior for the Cloze question: using negative points and using "all or nothing" plugins:

Using negative points

Use negative points to cancel positive points. For example:

This is a question with two sub-questions: {1:SHORTANSWER:=correct answer~%-100%*} and {1:SHORTANSWER:=correct answer~%-100%*}.
This is a question with three sub-questions: {1:SHORTANSWER:=correct answer~%-200%*}, {1:SHORTANSWER:=correct answer~%-200%*} and {1:SHORTANSWER:=correct answer~%-200%*}.
etc.

You can use this method with all question behaviours, except "Interactive with multiple tries" which does not treat negative points.

Using "all or nothing" plugins

Ask your administrator to install the Adaptive mode (all or nothing) plugin and/or the Deferred feedback (all or nothing). In the quiz settings and under "Question behaviour", set "How questions behave" to one of these modes.

Obviously, you can use this method only with the Adaptive (all or nothing) and Deferred feedback (all or nothing) modes.

Importing CLOZE questions

If you try importing directly as CLOZE this text:

Single line per question! Match the following cities with the correct state:
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}

The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!~%50%Marseille#No, that is the second largest city in France (after Paris).~*#Wrong answer. The capital of France is Paris, of course.}.

23+ 0.8 = {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 

You would get all three questions as different parts of ONE question. (NOTE see that there are no linebreaks between the { } !)

Multiple CLOZE questions can be imported using the XML format:

<?xml version="1.0" encoding="UTF-8"?>
<quiz>

<!-- question: 1  -->
<question type="cloze">
<name><text>Book Test #1</text>
</name>
<questiontext>
<text><![CDATA[..............]]></text>
</questiontext>
<generalfeedback>
<text></text>
</generalfeedback>
<shuffleanswers>0</shuffleanswers>
</question>

<!-- question: 2 -->
<question type="cloze">
<name><text>Book Test #2</text>
</name>
<questiontext>
<text><![CDATA[............]]></text>
</questiontext>
<generalfeedback>
<text></text>
</generalfeedback>
<shuffleanswers>0</shuffleanswers>
</question>

</quiz>

You would put the question text including CLOZE code in the ....... spaces.

Cloze editor plugin for the old TinyMCE editor

Cloze editor plugin for the new TinyMCE editor for Moodle 4.1 and newer

Cloze editor plugin for Atto

This new plugin for Moodle 3.1+ was developed by Daniel Thies and is available for download and install from the Moodle plugins database..

Question with 1 media (e.g. audio) and several subquestions

As described in this forum post, you can easily make a question where the student inspect a media (e.g. an audio file) and then has to answer several small multiple choice questions. The example below is from a Moodle 3.5.2+ site using the new Record audio tool in the Atto editor. The Record video tool will also let you add video as part of the question, if you want to.

CLOZE question with 1 audio and 3 sub-questions.png

Questions with student notes and feedback for teacher

You can easily make one/many/all question(s) with an optional field for student notes and/or feedback for the teacher, as requested in this forum thread. Note that only the first MULTICHOICE question is marked, and the two optional fields do not score positive nor negative points:

CLOZE question with student comment and teacher feedback.png

The full question for the above example is:

Which of the following options is the right answer ?
{1:MULTICHOICE_VS:~A wrong answer~Another wrong answer~Yet another wrong answer~%100%This is the only right answer}
Optionally:Write a personal note: {0:SHORTANSWER:~%0%I want to have a longer input box for the note.~%100%*}
Optionally:Send feedback to teacher:{0:SHORTANSWER:~%0%I want to have a longer input box for the feedback.~%100%*}

Troubleshooting: The equal sign (=) doesn't seem to work with SHORTANSWER.

On occasion, the Atto editor can insert HTML code, without your knowledge, into the text between { and } with the result that the Cloze question does not work as expected.

For example, if you have the following question text:

Moodle is the {:SA:=best~=leading} LMS.

the question must contain exactly {:SA:=best~=leading}. However, it is possible that the Atto editor has inserted an HTML tag, for example a <span> tag as follows:

Moodle is the {:SA:=best~<span>=</span>leading} LMS.

This can only be revealed if you view the HTML code of the question text. Check Displaying the HTML code to see how to do it.

So, if the Cloze question is not working as it should, check that it does not contain intrusive HTML tags. All you have to do is edit the HTML code of the question text and remove these tags.

See also

This information was drawn from: