<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/33/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ppichet</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/33/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ppichet"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/Special:Contributions/Ppichet"/>
	<updated>2026-04-16T21:52:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=120705</id>
		<title>Embedded Answers (Cloze) question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=120705"/>
		<updated>2015-10-21T03:48:35Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&#039;&#039;&#039;Embedded answers (Cloze)&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
You can link to an external web site that does create these questions from a graphical interface, see the &#039;&#039;[http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php Online Cloze Question quiz generator]&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
There is a [[Cloze editor module]] that will let you create these questions from a graphical interface within your Moodle site, but it will overwrite your current HTML editor.&lt;br /&gt;
&lt;br /&gt;
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&#039;s quiz module.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the passage of text (in Moodle format - see [[Embedded_Answers_%28Cloze%29_question_type#Format|Format]] below) into the &#039;question text&#039; field.&lt;br /&gt;
#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.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Embedded_Answers_%28Cloze%29_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#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.&lt;br /&gt;
#Click Save changes to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
==Question rendering==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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).([[User:Pierre Pichet|Pierre Pichet]] 15:37, 26 January 2008 (CST))&lt;br /&gt;
&lt;br /&gt;
The size will adjust to the length of the student response when displayed in the grading and feedback process.&lt;br /&gt;
&lt;br /&gt;
The size of the dropdown list or SELECT HTML ELEMENT (multichoice) adjusts itself automatically to the longest answer.&lt;br /&gt;
&lt;br /&gt;
==Format==&lt;br /&gt;
&lt;br /&gt;
Questions consist of a passage of text (in Moodle format) that has various sub-questions embedded within it, including&lt;br /&gt;
&lt;br /&gt;
* short answers (SHORTANSWER or SA or MW), case is unimportant,&lt;br /&gt;
* short answers (SHORTANSWER_C or SAC or MWC), case must match,&lt;br /&gt;
* numerical answers (NUMERICAL or NM),&lt;br /&gt;
* multiple choice (MULTICHOICE or MC), represented as a dropdown menu in-line in the text,&lt;br /&gt;
* multiple choice (MULTICHOICE_V or MCV), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_H or MCH), represented as a horizontal row of radio-buttons,&lt;br /&gt;
* when the quiz question behavior shuffle option IS SET YES, the following multiple choice sub-questions elements will be shuffled,&lt;br /&gt;
* multiple choice (MULTICHOICE_S or MCS), represented as a dropdown menu in-line in the text,&lt;br /&gt;
* multiple choice (MULTICHOICE_VS or MCVS), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_HS or MCHS), represented as a horizontal row of radio-buttons.&lt;br /&gt;
&lt;br /&gt;
The structure of  each cloze sub-question is identical:&lt;br /&gt;
:&#039;&#039;&#039;{&#039;&#039;&#039;  start the cloze sub-question with a bracket (AltGr+7)&lt;br /&gt;
:&#039;&#039;&#039;1&#039;&#039;&#039; define a grade for each cloze by  a number (optional). This used for calculation of question grading.&lt;br /&gt;
:&#039;&#039;&#039;:SHORTANSWER:&#039;&#039;&#039; define the type of cloze sub-question. Definition is bounded by &#039;:&#039;. &lt;br /&gt;
:&#039;&#039;&#039;~&#039;&#039;&#039; is a seperator between answer options&lt;br /&gt;
:&#039;&#039;&#039;=&#039;&#039;&#039; marks a correct answer&lt;br /&gt;
:&#039;&#039;&#039;#&#039;&#039;&#039; marks the beginning of an (optional) feedback message&lt;br /&gt;
:&#039;&#039;&#039;}&#039;&#039;&#039;  close the cloze sub-question at the end with a bracket (AltGr+0)&lt;br /&gt;
&lt;br /&gt;
Now a very simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{1:SHORTANSWER:=Berlin} is the capital of Germany.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For full details of the format for embedded-answers questions, see the [[Embedded_Answers_%28Cloze%29_question_type#Detailed_syntax_explanations|detailed syntax explanation]] below.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
If the correct answer contains } # ~ / &amp;quot; or \ you will have to escape them by putting a \ in front of each such character. But [[https://moodle.org/mod/forum/discuss.php?d=275299 this is tricky]]. The { shouldn&#039;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 &#039;&#039;the next answer&#039;&#039; or &#039;&#039;end of the short answer section&#039;&#039; respectively. Quotation signs: &amp;quot; can lead to trouble anyhow in both places. Use the HTML entity: &amp;amp; quot; (without the space between &#039;&#039;&amp;amp;&#039;&#039; and &#039;&#039;quot;&#039;&#039;). 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. &lt;br /&gt;
&lt;br /&gt;
See the notes further down about numerical embedded question!&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&lt;br /&gt;
====Example 1====&lt;br /&gt;
The following text creates a simple embedded-answers question:&lt;br /&gt;
&lt;br /&gt;
 Match the following cities with the correct state:&lt;br /&gt;
 * San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
 * Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
 The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!&lt;br /&gt;
 ~%50%Marseille#No, that is the second largest city in France (after&lt;br /&gt;
 Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
And the result will be:&lt;br /&gt;
 &lt;br /&gt;
[[Image:Cloze.gif|Cloze question type]] &lt;br /&gt;
&lt;br /&gt;
====Example 2====&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: 1em;border: 1px dashed #FFB53A;color: black;background-color: #f9f9f9;font-family: monospace;font-size:1.2em;&amp;quot;&amp;gt;&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
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}.&lt;br /&gt;
&lt;br /&gt;
The  multichoice question can also be shown in the vertical display of the standard moodle multiple choice.&lt;br /&gt;
{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}&lt;br /&gt;
&lt;br /&gt;
Or in an horizontal display that is included here in a table&lt;br /&gt;
{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}&lt;br /&gt;
&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
Note that addresses like www.moodle.org and smileys :-) all work as normal:&lt;br /&gt;
&lt;br /&gt;
a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}&lt;br /&gt;
&lt;br /&gt;
b) What grade would you give it? {3:NUMERICAL:=3:2}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Image:Cloze example.png]]&lt;br /&gt;
&lt;br /&gt;
Some things to note:&lt;br /&gt;
* The individual embedded answers are represented by the code in braces {}.&lt;br /&gt;
* The number at the start is the &#039;weight&#039;, so in this case each answer contributes an equal share of the overall grade.&lt;br /&gt;
* The correct option in each case is preceded either by an = sign or by %100%. &lt;br /&gt;
* The text appearing after the # that follows each option is the feedback that the student will see if they choose that option.&lt;br /&gt;
* If the student enters &#039;Marseille&#039; in the final example, they score 50% of the total grade.&lt;br /&gt;
* The asterisk * preceding the &amp;quot;Wrong answer&amp;quot; feedback in the final example means that the student will see this feedback if they enter anything other than &amp;quot;Paris&amp;quot; or &amp;quot;Marseille&amp;quot;.&lt;br /&gt;
* For multiple choice vertical or horizontal rendering there is no automatic numbering, though can added at each answer.&lt;br /&gt;
&lt;br /&gt;
==Detailed syntax explanations==&lt;br /&gt;
# all question items within a cloze-type question are coded inside curled braces { }&lt;br /&gt;
# 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 {:&lt;br /&gt;
# after the colon we have the item question type: MULTICHOICE, SHORTANSWER, NUMERICAL&lt;br /&gt;
# &#039;&#039;&#039;NOTE&#039;&#039;&#039;.- If you have installed the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 REGEXP question type plugin] you can also use the REGEXP question type&lt;br /&gt;
# the syntax for MULTICHOICE and SHORTANSWER is the same; the only difference is in the displaying of the item to the student&lt;br /&gt;
# the order of the various answers is indifferent (except if you want a catch-all for wrong answers, see #13 below)&lt;br /&gt;
# a correct answer is preceded with the equal sign = or a percentage (usually %100%) - &#039;&#039;&#039;Note&#039;&#039;&#039;: [[Talk:Embedded_Answers_(Cloze)_question_type| The equal sign (=) doesn&#039;t seem to work with SHORTANSWER.]]&lt;br /&gt;
# 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])&lt;br /&gt;
# you can allocate some points between 0 and 100 to some answers, if you put the appropriate percentage&lt;br /&gt;
# all answers except the first one are separated from one another by the tilde ~ sign&lt;br /&gt;
# 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&lt;br /&gt;
# 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 mouse hovering. The popup window has a title &amp;quot;feedback&amp;quot; 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.&lt;br /&gt;
# in the SHORTANSWER type you may want to put a catch-all (wrong) answer in order to send a &amp;quot;wrong, try again&amp;quot; feedback; you can do this by inserting an asterisk &#039;&#039;&#039;*&#039;&#039;&#039; as &#039;&#039;&#039;the very last expected answer&#039;&#039;&#039; in your formula&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numerical Cloze questions==	 &lt;br /&gt;
		 &lt;br /&gt;
From the student perspective, a numerical Cloze question looks just like a short-answer question or &#039;&#039;fill in the blanks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== False positives ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; the following examples of false positives do &#039;&#039;&#039;not&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
 More examples:	 &lt;br /&gt;
 0.5 accepts .5 0.5 ,5 0,5 0.500 5e-1 5E-1 but not 1/2 50% 	 &lt;br /&gt;
 50% accepts 50% 50.0% 5E1% 50/100 even &#039;&#039;&#039;50/1000 50&#039;&#039;&#039; but not 500/1000 0.5	 &lt;br /&gt;
 1/2 accepts 1/2 &#039;&#039;&#039;1/3 1twenty&#039;&#039;&#039; but not 2/4 0.5 0,5 3/6 50% ½	 &lt;br /&gt;
 ½ accepts ½	 &lt;br /&gt;
 HALF doesn&#039;t even accept HALF (maybe &#039;&#039;&#039;0&#039;&#039;&#039;?)	 &lt;br /&gt;
&lt;br /&gt;
If you want to accept several variants you can have them in the same {} but &#039;&#039;&#039;be careful, notice the &amp;quot;false positives&amp;quot; in bold&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
===Syntax for numerical Cloze questions===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
An example of the syntax used is shown below:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: &#039;&#039;&#039; It is preferable to write the code in &#039;source code&#039; 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! :(	&lt;br /&gt;
		 &lt;br /&gt;
 {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8	 &lt;br /&gt;
 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &lt;br /&gt;
	 &lt;br /&gt;
In this example:&lt;br /&gt;
* 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.&lt;br /&gt;
* NUMERICAL: says what kind of question it is. It must be in CAPS. &lt;br /&gt;
* =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.)	 &lt;br /&gt;
* #Feedback for correct answer 23.8 is preceded by #&lt;br /&gt;
* ~%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.&lt;br /&gt;
&lt;br /&gt;
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: &amp;amp;lt;sup&amp;amp;gt; &amp;amp;lt;/sup&amp;amp;gt;. You can even include pictures in the feedback popup, but you must clean out all &amp;quot; characters and save while still in source code mode (not WYSIWYG). So, this works in feedback popup:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=Something.gif /&amp;gt;}	 &lt;br /&gt;
but not this:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=&amp;quot;Something.gif&amp;quot; /&amp;gt;}	 &lt;br /&gt;
&lt;br /&gt;
(ALGEBRA and TEX filters don&#039;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.	 &lt;br /&gt;
&lt;br /&gt;
If you want to give feedback for any answer that didn&#039;t fit the intervals you already have specified feedback for, add some BIG general intervals, like for positive answers (if they aren&#039;t bigger than 20000 you could add:	 &lt;br /&gt;
 ~%0%10000.0001:10000#Feedback for unspecified not_right answers}	 &lt;br /&gt;
This would give feedback for anything from 0.0001 to 20000.0001 (that hadn&#039;t already gotten feedback). I didn&#039;t want to include 0 since that special case as well as negative ought to have specific reactions.	 &lt;br /&gt;
 ~%0%0#Hey! It can&#039;t be zero	 &lt;br /&gt;
 ~%0%-10000.0001:10000#We just want the size here,	 &lt;br /&gt;
 so a negative value is not what we want}			 &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
==Importing CLOZE questions==&lt;br /&gt;
If you try importing directly as CLOZE this text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Single line per question! Match the following cities with the correct state:&lt;br /&gt;
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
&lt;br /&gt;
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.}.&lt;br /&gt;
&lt;br /&gt;
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}. 	 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get all three questions as different parts of &#039;&#039;&#039;ONE question&#039;&#039;&#039;. (NOTE see that there are no linebreaks between the { } !)&lt;br /&gt;
&lt;br /&gt;
Multiple CLOZE questions can be imported using the XML format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;quiz&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 1  --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #1&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[..............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 2 --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #2&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You would put the question text including CLOZE code in the  .......  spaces.&lt;br /&gt;
&lt;br /&gt;
==Online Cloze Question quiz generator==&lt;br /&gt;
* There is a website to generate CLOZE quizzes for Moodle (1.9 and 2.x versions) and/or to try out the CLOZE editor integration for Moodle.&lt;br /&gt;
* This editor was built at the Chair of Applied English Linguistics at Universitaet Tuebingen, Germany, by Andreas Glombitza (andiglombitza(at)googlemail.com) and Achim Skuta (achim.skuta(at)googlemail.com).&lt;br /&gt;
* The authors are currently maintaining this software and webservice as a private project.&lt;br /&gt;
&lt;br /&gt;
Website: [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php]&lt;br /&gt;
 &lt;br /&gt;
==See also==&lt;br /&gt;
* See the [https://moodle.org/plugins/view.php?plugin=other_cloze Moodle plugin in the Moodle plugins database] that will let you create these questions from a graphical interface within your Moodle site, but it will overwrite your current tinymce editor.&lt;br /&gt;
* See the [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php online Cloze question generator].&lt;br /&gt;
* Download the newest version of the [[Cloze editor module]] for Moodle 1.9 and for Moodle 2.0 to 2.6) from [https://moodle.org/plugins/view.php?plugin=tinymce_clozeeditor the Moodle plugins database]&lt;br /&gt;
&lt;br /&gt;
This information was drawn from:&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36521 Is there a guide to using the cloze format?] forum discussion&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36430&amp;amp;parent=170308 Cloze-type question syntax] forum post&lt;br /&gt;
&lt;br /&gt;
[[de:Lückentext-Frage]]&lt;br /&gt;
[[es:Tipo de Pregunta con respuestas incrustadas (Cloze)]]&lt;br /&gt;
[[fr:Question Cloze à réponses intégrées]]&lt;br /&gt;
[[ja: 穴埋め問題 ( Cloze ) タイプ]]&lt;br /&gt;
[[zh:填空題(克漏字)]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=120704</id>
		<title>Embedded Answers (Cloze) question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=120704"/>
		<updated>2015-10-21T03:39:14Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&#039;&#039;&#039;Embedded answers (Cloze)&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
You can link to an external web site that does create these questions from a graphical interface, see the &#039;&#039;[http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php Online Cloze Question quiz generator]&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
There is a [[Cloze editor module]] that will let you create these questions from a graphical interface within your Moodle site, but it will overwrite your current HTML editor.&lt;br /&gt;
&lt;br /&gt;
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&#039;s quiz module.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the passage of text (in Moodle format - see [[Embedded_Answers_%28Cloze%29_question_type#Format|Format]] below) into the &#039;question text&#039; field.&lt;br /&gt;
#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.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Embedded_Answers_%28Cloze%29_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#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.&lt;br /&gt;
#Click Save changes to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
==Question rendering==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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).([[User:Pierre Pichet|Pierre Pichet]] 15:37, 26 January 2008 (CST))&lt;br /&gt;
&lt;br /&gt;
The size will adjust to the length of the student response when displayed in the grading and feedback process.&lt;br /&gt;
&lt;br /&gt;
The size of the dropdown list or SELECT HTML ELEMENT (multichoice) adjusts itself automatically to the longest answer.&lt;br /&gt;
&lt;br /&gt;
==Format==&lt;br /&gt;
&lt;br /&gt;
Questions consist of a passage of text (in Moodle format) that has various sub-questions embedded within it, including&lt;br /&gt;
&lt;br /&gt;
* short answers (SHORTANSWER or SA or MW), case is unimportant,&lt;br /&gt;
* short answers (SHORTANSWER_C or SAC or MWC), case must match,&lt;br /&gt;
* numerical answers (NUMERICAL or NM),&lt;br /&gt;
* multiple choice (MULTICHOICE or MC), represented as a dropdown menu in-line in the text,&lt;br /&gt;
* multiple choice (MULTICHOICE_V or MCV), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_H or MCH), represented as a horizontal row of radio-buttons,&lt;br /&gt;
* when the quiz shuffle option IS SET ON, the following multiple choice sub-questions elements will shuffle,&lt;br /&gt;
* multiple choice (MULTICHOICE_S or MCS), represented as a dropdown menu in-line in the text,&lt;br /&gt;
* multiple choice (MULTICHOICE_VS or MCVS), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_HS or MCHS), represented as a horizontal row of radio-buttons.&lt;br /&gt;
&lt;br /&gt;
The structure of  each cloze sub-question is identical:&lt;br /&gt;
:&#039;&#039;&#039;{&#039;&#039;&#039;  start the cloze sub-question with a bracket (AltGr+7)&lt;br /&gt;
:&#039;&#039;&#039;1&#039;&#039;&#039; define a grade for each cloze by  a number (optional). This used for calculation of question grading.&lt;br /&gt;
:&#039;&#039;&#039;:SHORTANSWER:&#039;&#039;&#039; define the type of cloze sub-question. Definition is bounded by &#039;:&#039;. &lt;br /&gt;
:&#039;&#039;&#039;~&#039;&#039;&#039; is a seperator between answer options&lt;br /&gt;
:&#039;&#039;&#039;=&#039;&#039;&#039; marks a correct answer&lt;br /&gt;
:&#039;&#039;&#039;#&#039;&#039;&#039; marks the beginning of an (optional) feedback message&lt;br /&gt;
:&#039;&#039;&#039;}&#039;&#039;&#039;  close the cloze sub-question at the end with a bracket (AltGr+0)&lt;br /&gt;
&lt;br /&gt;
Now a very simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{1:SHORTANSWER:=Berlin} is the capital of Germany.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For full details of the format for embedded-answers questions, see the [[Embedded_Answers_%28Cloze%29_question_type#Detailed_syntax_explanations|detailed syntax explanation]] below.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
If the correct answer contains } # ~ / &amp;quot; or \ you will have to escape them by putting a \ in front of each such character. But [[https://moodle.org/mod/forum/discuss.php?d=275299 this is tricky]]. The { shouldn&#039;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 &#039;&#039;the next answer&#039;&#039; or &#039;&#039;end of the short answer section&#039;&#039; respectively. Quotation signs: &amp;quot; can lead to trouble anyhow in both places. Use the HTML entity: &amp;amp; quot; (without the space between &#039;&#039;&amp;amp;&#039;&#039; and &#039;&#039;quot;&#039;&#039;). 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. &lt;br /&gt;
&lt;br /&gt;
See the notes further down about numerical embedded question!&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&lt;br /&gt;
====Example 1====&lt;br /&gt;
The following text creates a simple embedded-answers question:&lt;br /&gt;
&lt;br /&gt;
 Match the following cities with the correct state:&lt;br /&gt;
 * San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
 * Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
 The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!&lt;br /&gt;
 ~%50%Marseille#No, that is the second largest city in France (after&lt;br /&gt;
 Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
And the result will be:&lt;br /&gt;
 &lt;br /&gt;
[[Image:Cloze.gif|Cloze question type]] &lt;br /&gt;
&lt;br /&gt;
====Example 2====&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: 1em;border: 1px dashed #FFB53A;color: black;background-color: #f9f9f9;font-family: monospace;font-size:1.2em;&amp;quot;&amp;gt;&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
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}.&lt;br /&gt;
&lt;br /&gt;
The  multichoice question can also be shown in the vertical display of the standard moodle multiple choice.&lt;br /&gt;
{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}&lt;br /&gt;
&lt;br /&gt;
Or in an horizontal display that is included here in a table&lt;br /&gt;
{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}&lt;br /&gt;
&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
Note that addresses like www.moodle.org and smileys :-) all work as normal:&lt;br /&gt;
&lt;br /&gt;
a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}&lt;br /&gt;
&lt;br /&gt;
b) What grade would you give it? {3:NUMERICAL:=3:2}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Image:Cloze example.png]]&lt;br /&gt;
&lt;br /&gt;
Some things to note:&lt;br /&gt;
* The individual embedded answers are represented by the code in braces {}.&lt;br /&gt;
* The number at the start is the &#039;weight&#039;, so in this case each answer contributes an equal share of the overall grade.&lt;br /&gt;
* The correct option in each case is preceded either by an = sign or by %100%. &lt;br /&gt;
* The text appearing after the # that follows each option is the feedback that the student will see if they choose that option.&lt;br /&gt;
* If the student enters &#039;Marseille&#039; in the final example, they score 50% of the total grade.&lt;br /&gt;
* The asterisk * preceding the &amp;quot;Wrong answer&amp;quot; feedback in the final example means that the student will see this feedback if they enter anything other than &amp;quot;Paris&amp;quot; or &amp;quot;Marseille&amp;quot;.&lt;br /&gt;
* For multiple choice vertical or horizontal rendering there is no automatic numbering, though can added at each answer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Detailed syntax explanations==&lt;br /&gt;
# all question items within a cloze-type question are coded inside curled braces { }&lt;br /&gt;
# 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 {:&lt;br /&gt;
# after the colon we have the item question type: MULTICHOICE, SHORTANSWER, NUMERICAL&lt;br /&gt;
# &#039;&#039;&#039;NOTE&#039;&#039;&#039;.- If you have installed the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 REGEXP question type plugin] you can also use the REGEXP question type&lt;br /&gt;
# the syntax for MULTICHOICE and SHORTANSWER is the same; the only difference is in the displaying of the item to the student&lt;br /&gt;
# the order of the various answers is indifferent (except if you want a catch-all for wrong answers, see #13 below)&lt;br /&gt;
# a correct answer is preceded with the equal sign = or a percentage (usually %100%) - &#039;&#039;&#039;Note&#039;&#039;&#039;: [[Talk:Embedded_Answers_(Cloze)_question_type| The equal sign (=) doesn&#039;t seem to work with SHORTANSWER.]]&lt;br /&gt;
# 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])&lt;br /&gt;
# you can allocate some points between 0 and 100 to some answers, if you put the appropriate percentage&lt;br /&gt;
# all answers except the first one are separated from one another by the tilde ~ sign&lt;br /&gt;
# 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&lt;br /&gt;
# 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 mouse hovering. The popup window has a title &amp;quot;feedback&amp;quot; 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.&lt;br /&gt;
# in the SHORTANSWER type you may want to put a catch-all (wrong) answer in order to send a &amp;quot;wrong, try again&amp;quot; feedback; you can do this by inserting an asterisk &#039;&#039;&#039;*&#039;&#039;&#039; as &#039;&#039;&#039;the very last expected answer&#039;&#039;&#039; in your formula&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numerical Cloze questions==	 &lt;br /&gt;
		 &lt;br /&gt;
From the student perspective, a numerical Cloze question looks just like a short-answer question or &#039;&#039;fill in the blanks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== False positives ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; the following examples of false positives do &#039;&#039;&#039;not&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
 More examples:	 &lt;br /&gt;
 0.5 accepts .5 0.5 ,5 0,5 0.500 5e-1 5E-1 but not 1/2 50% 	 &lt;br /&gt;
 50% accepts 50% 50.0% 5E1% 50/100 even &#039;&#039;&#039;50/1000 50&#039;&#039;&#039; but not 500/1000 0.5	 &lt;br /&gt;
 1/2 accepts 1/2 &#039;&#039;&#039;1/3 1twenty&#039;&#039;&#039; but not 2/4 0.5 0,5 3/6 50% ½	 &lt;br /&gt;
 ½ accepts ½	 &lt;br /&gt;
 HALF doesn&#039;t even accept HALF (maybe &#039;&#039;&#039;0&#039;&#039;&#039;?)	 &lt;br /&gt;
&lt;br /&gt;
If you want to accept several variants you can have them in the same {} but &#039;&#039;&#039;be careful, notice the &amp;quot;false positives&amp;quot; in bold&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
===Syntax for numerical Cloze questions===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
An example of the syntax used is shown below:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: &#039;&#039;&#039; It is preferable to write the code in &#039;source code&#039; 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! :(	&lt;br /&gt;
		 &lt;br /&gt;
 {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8	 &lt;br /&gt;
 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &lt;br /&gt;
	 &lt;br /&gt;
In this example:&lt;br /&gt;
* 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.&lt;br /&gt;
* NUMERICAL: says what kind of question it is. It must be in CAPS. &lt;br /&gt;
* =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.)	 &lt;br /&gt;
* #Feedback for correct answer 23.8 is preceded by #&lt;br /&gt;
* ~%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.&lt;br /&gt;
&lt;br /&gt;
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: &amp;amp;lt;sup&amp;amp;gt; &amp;amp;lt;/sup&amp;amp;gt;. You can even include pictures in the feedback popup, but you must clean out all &amp;quot; characters and save while still in source code mode (not WYSIWYG). So, this works in feedback popup:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=Something.gif /&amp;gt;}	 &lt;br /&gt;
but not this:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=&amp;quot;Something.gif&amp;quot; /&amp;gt;}	 &lt;br /&gt;
&lt;br /&gt;
(ALGEBRA and TEX filters don&#039;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.	 &lt;br /&gt;
&lt;br /&gt;
If you want to give feedback for any answer that didn&#039;t fit the intervals you already have specified feedback for, add some BIG general intervals, like for positive answers (if they aren&#039;t bigger than 20000 you could add:	 &lt;br /&gt;
 ~%0%10000.0001:10000#Feedback for unspecified not_right answers}	 &lt;br /&gt;
This would give feedback for anything from 0.0001 to 20000.0001 (that hadn&#039;t already gotten feedback). I didn&#039;t want to include 0 since that special case as well as negative ought to have specific reactions.	 &lt;br /&gt;
 ~%0%0#Hey! It can&#039;t be zero	 &lt;br /&gt;
 ~%0%-10000.0001:10000#We just want the size here,	 &lt;br /&gt;
 so a negative value is not what we want}			 &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
==Importing CLOZE questions==&lt;br /&gt;
If you try importing directly as CLOZE this text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Single line per question! Match the following cities with the correct state:&lt;br /&gt;
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
&lt;br /&gt;
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.}.&lt;br /&gt;
&lt;br /&gt;
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}. 	 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get all three questions as different parts of &#039;&#039;&#039;ONE question&#039;&#039;&#039;. (NOTE see that there are no linebreaks between the { } !)&lt;br /&gt;
&lt;br /&gt;
Multiple CLOZE questions can be imported using the XML format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;quiz&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 1  --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #1&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[..............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 2 --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #2&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You would put the question text including CLOZE code in the  .......  spaces.&lt;br /&gt;
&lt;br /&gt;
==Online Cloze Question quiz generator==&lt;br /&gt;
* There is a website to generate CLOZE quizzes for Moodle (1.9 and 2.x versions) and/or to try out the CLOZE editor integration for Moodle.&lt;br /&gt;
* This editor was built at the Chair of Applied English Linguistics at Universitaet Tuebingen, Germany, by Andreas Glombitza (andiglombitza(at)googlemail.com) and Achim Skuta (achim.skuta(at)googlemail.com).&lt;br /&gt;
* The authors are currently maintaining this software and webservice as a private project.&lt;br /&gt;
&lt;br /&gt;
Website: [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php]&lt;br /&gt;
 &lt;br /&gt;
==See also==&lt;br /&gt;
* See the [https://moodle.org/plugins/view.php?plugin=other_cloze Moodle plugin in the Moodle plugins database] that will let you create these questions from a graphical interface within your Moodle site, but it will overwrite your current tinymce editor.&lt;br /&gt;
* See the [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php online Cloze question generator].&lt;br /&gt;
* Download the newest version of the [[Cloze editor module]] for Moodle 1.9 and for Moodle 2.0 to 2.6) from [https://moodle.org/plugins/view.php?plugin=tinymce_clozeeditor the Moodle plugins database]&lt;br /&gt;
&lt;br /&gt;
This information was drawn from:&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36521 Is there a guide to using the cloze format?] forum discussion&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36430&amp;amp;parent=170308 Cloze-type question syntax] forum post&lt;br /&gt;
&lt;br /&gt;
[[de:Lückentext-Frage]]&lt;br /&gt;
[[es:Tipo de Pregunta con respuestas incrustadas (Cloze)]]&lt;br /&gt;
[[fr:Question Cloze à réponses intégrées]]&lt;br /&gt;
[[ja: 穴埋め問題 ( Cloze ) タイプ]]&lt;br /&gt;
[[zh:填空題(克漏字)]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=120703</id>
		<title>Embedded Answers (Cloze) question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Embedded_Answers_(Cloze)_question_type&amp;diff=120703"/>
		<updated>2015-10-21T03:35:09Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: First modifications related to MDL-38214, to be completed&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&#039;&#039;&#039;Embedded answers (Cloze)&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
You can link to an external web site that does create these questions from a graphical interface, see the &#039;&#039;[http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php Online Cloze Question quiz generator]&#039;&#039; below.&lt;br /&gt;
&lt;br /&gt;
There is a [[Cloze editor module]] that will let you create these questions from a graphical interface within your Moodle site, but it will overwrite your current HTML editor.&lt;br /&gt;
&lt;br /&gt;
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&#039;s quiz module.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the passage of text (in Moodle format - see [[Embedded_Answers_%28Cloze%29_question_type#Format|Format]] below) into the &#039;question text&#039; field.&lt;br /&gt;
#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.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Embedded_Answers_%28Cloze%29_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#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.&lt;br /&gt;
#Click Save changes to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
==Question rendering==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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).([[User:Pierre Pichet|Pierre Pichet]] 15:37, 26 January 2008 (CST))&lt;br /&gt;
&lt;br /&gt;
The size will adjust to the length of the student response when displayed in the grading and feedback process.&lt;br /&gt;
&lt;br /&gt;
The size of the dropdown list or SELECT HTML ELEMENT (multichoice) adjusts itself automatically to the longest answer.&lt;br /&gt;
&lt;br /&gt;
==Format==&lt;br /&gt;
&lt;br /&gt;
Questions consist of a passage of text (in Moodle format) that has various sub-questions embedded within it, including&lt;br /&gt;
&lt;br /&gt;
* short answers (SHORTANSWER or SA or MW), case is unimportant,&lt;br /&gt;
* short answers (SHORTANSWER_C or SAC or MWC), case must match,&lt;br /&gt;
* numerical answers (NUMERICAL or NM),&lt;br /&gt;
* multiple choice (MULTICHOICE or MC), represented as a dropdown menu in-line in the text&lt;br /&gt;
* multiple choice (MULTICHOICE_V or MCV), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_H or MCH), represented as a horizontal row of radio-buttons.&lt;br /&gt;
* when the quiz shuffle option IS SET, the following multiple choice sub-questions elements will shuffle,&lt;br /&gt;
* multiple choice (MULTICHOICE_S or MCS), represented as a dropdown menu in-line in the text&lt;br /&gt;
* multiple choice (MULTICHOICE_VS or MCVS), represented as a vertical column of radio buttons, or&lt;br /&gt;
* multiple choice (MULTICHOICE_HS or MCHS), represented as a horizontal row of radio-buttons.&lt;br /&gt;
&lt;br /&gt;
The structure of  each cloze sub-question is identical:&lt;br /&gt;
:&#039;&#039;&#039;{&#039;&#039;&#039;  start the cloze sub-question with a bracket (AltGr+7)&lt;br /&gt;
:&#039;&#039;&#039;1&#039;&#039;&#039; define a grade for each cloze by  a number (optional). This used for calculation of question grading.&lt;br /&gt;
:&#039;&#039;&#039;:SHORTANSWER:&#039;&#039;&#039; define the type of cloze sub-question. Definition is bounded by &#039;:&#039;. &lt;br /&gt;
:&#039;&#039;&#039;~&#039;&#039;&#039; is a seperator between answer options&lt;br /&gt;
:&#039;&#039;&#039;=&#039;&#039;&#039; marks a correct answer&lt;br /&gt;
:&#039;&#039;&#039;#&#039;&#039;&#039; marks the beginning of an (optional) feedback message&lt;br /&gt;
:&#039;&#039;&#039;}&#039;&#039;&#039;  close the cloze sub-question at the end with a bracket (AltGr+0)&lt;br /&gt;
&lt;br /&gt;
Now a very simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{1:SHORTANSWER:=Berlin} is the capital of Germany.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For full details of the format for embedded-answers questions, see the [[Embedded_Answers_%28Cloze%29_question_type#Detailed_syntax_explanations|detailed syntax explanation]] below.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
If the correct answer contains } # ~ / &amp;quot; or \ you will have to escape them by putting a \ in front of each such character. But [[https://moodle.org/mod/forum/discuss.php?d=275299 this is tricky]]. The { shouldn&#039;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 &#039;&#039;the next answer&#039;&#039; or &#039;&#039;end of the short answer section&#039;&#039; respectively. Quotation signs: &amp;quot; can lead to trouble anyhow in both places. Use the HTML entity: &amp;amp; quot; (without the space between &#039;&#039;&amp;amp;&#039;&#039; and &#039;&#039;quot;&#039;&#039;). 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. &lt;br /&gt;
&lt;br /&gt;
See the notes further down about numerical embedded question!&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&lt;br /&gt;
====Example 1====&lt;br /&gt;
The following text creates a simple embedded-answers question:&lt;br /&gt;
&lt;br /&gt;
 Match the following cities with the correct state:&lt;br /&gt;
 * San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
 * Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
 * Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
 The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!&lt;br /&gt;
 ~%50%Marseille#No, that is the second largest city in France (after&lt;br /&gt;
 Paris).~*#Wrong answer. The capital of France is Paris, of course.}.&lt;br /&gt;
&lt;br /&gt;
And the result will be:&lt;br /&gt;
 &lt;br /&gt;
[[Image:Cloze.gif|Cloze question type]] &lt;br /&gt;
&lt;br /&gt;
====Example 2====&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: 1em;border: 1px dashed #FFB53A;color: black;background-color: #f9f9f9;font-family: monospace;font-size:1.2em;&amp;quot;&amp;gt;&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
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}.&lt;br /&gt;
&lt;br /&gt;
The  multichoice question can also be shown in the vertical display of the standard moodle multiple choice.&lt;br /&gt;
{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}&lt;br /&gt;
&lt;br /&gt;
Or in an horizontal display that is included here in a table&lt;br /&gt;
{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}&lt;br /&gt;
&lt;br /&gt;
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}&lt;br /&gt;
&lt;br /&gt;
Note that addresses like www.moodle.org and smileys :-) all work as normal:&lt;br /&gt;
&lt;br /&gt;
a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}&lt;br /&gt;
&lt;br /&gt;
b) What grade would you give it? {3:NUMERICAL:=3:2}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Image:Cloze example.png]]&lt;br /&gt;
&lt;br /&gt;
Some things to note:&lt;br /&gt;
* The individual embedded answers are represented by the code in braces {}.&lt;br /&gt;
* The number at the start is the &#039;weight&#039;, so in this case each answer contributes an equal share of the overall grade.&lt;br /&gt;
* The correct option in each case is preceded either by an = sign or by %100%. &lt;br /&gt;
* The text appearing after the # that follows each option is the feedback that the student will see if they choose that option.&lt;br /&gt;
* If the student enters &#039;Marseille&#039; in the final example, they score 50% of the total grade.&lt;br /&gt;
* The asterisk * preceding the &amp;quot;Wrong answer&amp;quot; feedback in the final example means that the student will see this feedback if they enter anything other than &amp;quot;Paris&amp;quot; or &amp;quot;Marseille&amp;quot;.&lt;br /&gt;
* For multiple choice vertical or horizontal rendering there is no automatic numbering, though can added at each answer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Detailed syntax explanations==&lt;br /&gt;
# all question items within a cloze-type question are coded inside curled braces { }&lt;br /&gt;
# 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 {:&lt;br /&gt;
# after the colon we have the item question type: MULTICHOICE, SHORTANSWER, NUMERICAL&lt;br /&gt;
# &#039;&#039;&#039;NOTE&#039;&#039;&#039;.- If you have installed the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=338 REGEXP question type plugin] you can also use the REGEXP question type&lt;br /&gt;
# the syntax for MULTICHOICE and SHORTANSWER is the same; the only difference is in the displaying of the item to the student&lt;br /&gt;
# the order of the various answers is indifferent (except if you want a catch-all for wrong answers, see #13 below)&lt;br /&gt;
# a correct answer is preceded with the equal sign = or a percentage (usually %100%) - &#039;&#039;&#039;Note&#039;&#039;&#039;: [[Talk:Embedded_Answers_(Cloze)_question_type| The equal sign (=) doesn&#039;t seem to work with SHORTANSWER.]]&lt;br /&gt;
# 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])&lt;br /&gt;
# you can allocate some points between 0 and 100 to some answers, if you put the appropriate percentage&lt;br /&gt;
# all answers except the first one are separated from one another by the tilde ~ sign&lt;br /&gt;
# 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&lt;br /&gt;
# 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 mouse hovering. The popup window has a title &amp;quot;feedback&amp;quot; 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.&lt;br /&gt;
# in the SHORTANSWER type you may want to put a catch-all (wrong) answer in order to send a &amp;quot;wrong, try again&amp;quot; feedback; you can do this by inserting an asterisk &#039;&#039;&#039;*&#039;&#039;&#039; as &#039;&#039;&#039;the very last expected answer&#039;&#039;&#039; in your formula&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numerical Cloze questions==	 &lt;br /&gt;
		 &lt;br /&gt;
From the student perspective, a numerical Cloze question looks just like a short-answer question or &#039;&#039;fill in the blanks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== False positives ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; the following examples of false positives do &#039;&#039;&#039;not&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
 More examples:	 &lt;br /&gt;
 0.5 accepts .5 0.5 ,5 0,5 0.500 5e-1 5E-1 but not 1/2 50% 	 &lt;br /&gt;
 50% accepts 50% 50.0% 5E1% 50/100 even &#039;&#039;&#039;50/1000 50&#039;&#039;&#039; but not 500/1000 0.5	 &lt;br /&gt;
 1/2 accepts 1/2 &#039;&#039;&#039;1/3 1twenty&#039;&#039;&#039; but not 2/4 0.5 0,5 3/6 50% ½	 &lt;br /&gt;
 ½ accepts ½	 &lt;br /&gt;
 HALF doesn&#039;t even accept HALF (maybe &#039;&#039;&#039;0&#039;&#039;&#039;?)	 &lt;br /&gt;
&lt;br /&gt;
If you want to accept several variants you can have them in the same {} but &#039;&#039;&#039;be careful, notice the &amp;quot;false positives&amp;quot; in bold&#039;&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
===Syntax for numerical Cloze questions===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
An example of the syntax used is shown below:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: &#039;&#039;&#039; It is preferable to write the code in &#039;source code&#039; 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! :(	&lt;br /&gt;
		 &lt;br /&gt;
 {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8	 &lt;br /&gt;
 ~%50%23.8:2#Feedback for ½credit near correct answer}. 	 &lt;br /&gt;
	 &lt;br /&gt;
In this example:&lt;br /&gt;
* 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.&lt;br /&gt;
* NUMERICAL: says what kind of question it is. It must be in CAPS. &lt;br /&gt;
* =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.)	 &lt;br /&gt;
* #Feedback for correct answer 23.8 is preceded by #&lt;br /&gt;
* ~%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.&lt;br /&gt;
&lt;br /&gt;
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: &amp;amp;lt;sup&amp;amp;gt; &amp;amp;lt;/sup&amp;amp;gt;. You can even include pictures in the feedback popup, but you must clean out all &amp;quot; characters and save while still in source code mode (not WYSIWYG). So, this works in feedback popup:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=Something.gif /&amp;gt;}	 &lt;br /&gt;
but not this:&lt;br /&gt;
 #See this picture:&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;img src=&amp;quot;Something.gif&amp;quot; /&amp;gt;}	 &lt;br /&gt;
&lt;br /&gt;
(ALGEBRA and TEX filters don&#039;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.	 &lt;br /&gt;
&lt;br /&gt;
If you want to give feedback for any answer that didn&#039;t fit the intervals you already have specified feedback for, add some BIG general intervals, like for positive answers (if they aren&#039;t bigger than 20000 you could add:	 &lt;br /&gt;
 ~%0%10000.0001:10000#Feedback for unspecified not_right answers}	 &lt;br /&gt;
This would give feedback for anything from 0.0001 to 20000.0001 (that hadn&#039;t already gotten feedback). I didn&#039;t want to include 0 since that special case as well as negative ought to have specific reactions.	 &lt;br /&gt;
 ~%0%0#Hey! It can&#039;t be zero	 &lt;br /&gt;
 ~%0%-10000.0001:10000#We just want the size here,	 &lt;br /&gt;
 so a negative value is not what we want}			 &lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
==Importing CLOZE questions==&lt;br /&gt;
If you try importing directly as CLOZE this text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Single line per question! Match the following cities with the correct state:&lt;br /&gt;
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}&lt;br /&gt;
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}&lt;br /&gt;
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}&lt;br /&gt;
&lt;br /&gt;
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.}.&lt;br /&gt;
&lt;br /&gt;
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}. 	 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get all three questions as different parts of &#039;&#039;&#039;ONE question&#039;&#039;&#039;. (NOTE see that there are no linebreaks between the { } !)&lt;br /&gt;
&lt;br /&gt;
Multiple CLOZE questions can be imported using the XML format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;quiz&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 1  --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #1&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[..............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- question: 2 --&amp;gt;&lt;br /&gt;
&amp;lt;question type=&amp;quot;cloze&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;&amp;lt;text&amp;gt;Book Test #2&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;questiontext&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;![CDATA[............]]&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/questiontext&amp;gt;&lt;br /&gt;
&amp;lt;generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;text&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/generalfeedback&amp;gt;&lt;br /&gt;
&amp;lt;shuffleanswers&amp;gt;0&amp;lt;/shuffleanswers&amp;gt;&lt;br /&gt;
&amp;lt;/question&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You would put the question text including CLOZE code in the  .......  spaces.&lt;br /&gt;
&lt;br /&gt;
==Online Cloze Question quiz generator==&lt;br /&gt;
* There is a website to generate CLOZE quizzes for Moodle (1.9 and 2.x versions) and/or to try out the CLOZE editor integration for Moodle.&lt;br /&gt;
* This editor was built at the Chair of Applied English Linguistics at Universitaet Tuebingen, Germany, by Andreas Glombitza (andiglombitza(at)googlemail.com) and Achim Skuta (achim.skuta(at)googlemail.com).&lt;br /&gt;
* The authors are currently maintaining this software and webservice as a private project.&lt;br /&gt;
&lt;br /&gt;
Website: [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php]&lt;br /&gt;
 &lt;br /&gt;
==See also==&lt;br /&gt;
* See the [https://moodle.org/plugins/view.php?plugin=other_cloze Moodle plugin in the Moodle plugins database] that will let you create these questions from a graphical interface within your Moodle site, but it will overwrite your current tinymce editor.&lt;br /&gt;
* See the [http://projects.ael.uni-tuebingen.de/quiz/htmlarea/index.php online Cloze question generator].&lt;br /&gt;
* Download the newest version of the [[Cloze editor module]] for Moodle 1.9 and for Moodle 2.0 to 2.6) from [https://moodle.org/plugins/view.php?plugin=tinymce_clozeeditor the Moodle plugins database]&lt;br /&gt;
&lt;br /&gt;
This information was drawn from:&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36521 Is there a guide to using the cloze format?] forum discussion&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=36430&amp;amp;parent=170308 Cloze-type question syntax] forum post&lt;br /&gt;
&lt;br /&gt;
[[de:Lückentext-Frage]]&lt;br /&gt;
[[es:Tipo de Pregunta con respuestas incrustadas (Cloze)]]&lt;br /&gt;
[[fr:Question Cloze à réponses intégrées]]&lt;br /&gt;
[[ja: 穴埋め問題 ( Cloze ) タイプ]]&lt;br /&gt;
[[zh:填空題(克漏字)]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=101494</id>
		<title>Calculated question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=101494"/>
		<updated>2012-10-25T15:26:04Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: using common variable names enclosed in curly braces to create the wildcards.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
Calculated questions offer a way to create individual numerical questions by the use of wildcards  (i.e you can use common variables names as &#039;&#039;&#039;x&#039;&#039;&#039; , &#039;&#039;&#039;y&#039;&#039;&#039;  enclosed  in curly braces  to create the  wildcards &#039;&#039;&#039;{x}&#039;&#039;&#039; and &#039;&#039;&#039;{y}&#039;&#039;&#039;) that are substituted with random values when the quiz is taken.&lt;br /&gt;
 &lt;br /&gt;
For example, if you want to create a large number of &#039;&#039;&#039;&amp;quot;Calculate the area of a rectangle&amp;quot;&#039;&#039;&#039; problems to drill your students, you could create a question with two wildcards (i.e. &#039;&#039;&#039;{base}&#039;&#039;&#039;, &#039;&#039;&#039;{height}&#039;&#039;&#039; created from the common &#039;&#039;&#039;base&#039;&#039;&#039;, &#039;&#039;&#039;height&#039;&#039;&#039; variable names)  and put in the &amp;quot;&#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039;&amp;quot; input field  &#039;&#039;&#039;{base}&#039;&#039;&#039; * &#039;&#039;&#039;{height}&#039;&#039;&#039; ( * being the multiplication sign ).&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039; {base}*{height}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
When a student takes the test, Moodle will randomly select values for &#039;&#039;&#039;{base}&#039;&#039;&#039; and &#039;&#039;&#039;{height}&#039;&#039;&#039; and grade the response using the result of the &#039;&#039;&#039;Correct Answer Formula&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
The test will very rarely appear the same way twice.&lt;br /&gt;
&lt;br /&gt;
== Is this really the question type for you? ==&lt;br /&gt;
The main purpose of the calculated question is to create multiple versions of a question with different numerical values. This means you must have &#039;&#039;&#039;at least one&#039;&#039;&#039; wildcard in one of the answers.&lt;br /&gt;
 &lt;br /&gt;
If you don&#039;t need a random element, use the [[Numerical question type]] instead.&lt;br /&gt;
== Simple calculated question type   ==&lt;br /&gt;
&lt;br /&gt;
The [[Simple calculated question type|simple calculated]] question offers the most used features of the calculated question with a much simpler creation interface.&lt;br /&gt;
&lt;br /&gt;
==Wildcards and datasets==&lt;br /&gt;
&lt;br /&gt;
When Moodle delivers a Calculated question to the student, the wildcards are replaced with randomly-selected values. However, these values are not completely random - rather, they are randomly selected from a pre-defined &#039;&#039;dataset&#039;&#039; of possible values. This allows you some control over the possible values chosen - for example, in order to make sure the numbers are realistic.&lt;br /&gt;
&lt;br /&gt;
These datasets can be &#039;&#039;private&#039;&#039; or &#039;&#039;shared&#039;&#039; - private datasets are used by one wildcard within one calculated question; shared datasets are used by one wildcard within all calculated questions that use it.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
To create (or modify) a calculated question there are three pages to work through. The instructions below take you through the pages, step by step:&lt;br /&gt;
&lt;br /&gt;
===Page 1. Editing a Calculated question ===&lt;br /&gt;
&lt;br /&gt;
#Select the question &#039;&#039;&#039;category&#039;&#039;&#039;&lt;br /&gt;
#Any shared wildcards for this category are listed beneath. If you change category, you&#039;ll need to click the &amp;quot;Update the category&amp;quot; button to refresh this list. There may not be any shared wildcards yet - if not, you can create them later if you wish.&lt;br /&gt;
#Give the question a descriptive &#039;&#039;&#039;name&#039;&#039;&#039; - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the &#039;&#039;&#039;question text&#039;&#039;&#039;. This should be the question you want the student to answer, and it must include all the information they need to calculate an answer. Therefore it must contain at least one wildcard, inside curly braces. For example, if you wanted the student to sum numbers A and B, the question text might read: &amp;quot;What is {A} + {B}?&amp;quot; You may also include quantities computed from wildcards using the syntax &amp;quot;{=...}: for example, the question &amp;quot;What is {={A}+{B}} - {A}?&amp;quot; with wildcard values A=4 and B=3 would display as &amp;quot;What is 7 - 4?&amp;quot;&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices. If you want more control over how the image appears, include it in the question text above, using the HTML editor.&lt;br /&gt;
#Set the &#039;&#039;&#039;default question grade&#039;&#039;&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;&#039;&#039;Penalty factor&#039;&#039;&#039; (see [[Calculated_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#&#039;&#039;Moodle 1.7+:&#039;&#039; If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Next add the &#039;&#039;&#039;formula for the answer&#039;&#039;&#039;. This formula must contain at least the wildcards that appear in the question text. See [[Calculated_question_type#Correct_answer_formula_syntax|Correct answer formula syntax]] for further details.&lt;br /&gt;
# Choose the &#039;&#039;&#039;grade&#039;&#039;&#039; that the student will get for this question if they give this answer. This should be a percentage of the total marks available. For example, you could give 100% for a correct answer, and 50% for an answer that is nearly right. &#039;&#039;&#039;One of the answers must have a 100% grade&#039;&#039;&#039;.&lt;br /&gt;
#Determine the &#039;&#039;&#039;tolerance&#039;&#039;&#039; for error that you will accept in the answer. The tolerance and tolerance type settings combine to give a range of acceptable scores. So, if tolerance = t, correct answer = x and the difference between the user&#039;s answer and the correct answer is dx, then the tolerance types are as follows:&lt;br /&gt;
##Nominal - mark correct if dx &amp;lt;= t&lt;br /&gt;
##Relative - mark correct if dx / x &amp;lt;= t&lt;br /&gt;
##Geometric - mark correct if dx² / x² &amp;lt;= t²&lt;br /&gt;
# The next 2 settings, &amp;quot;Correct answer shows&amp;quot; and &amp;quot;Format&amp;quot; determine the &#039;&#039;&#039;precision&#039;&#039;&#039; of the answer. Use these to select the number of decimal places or significant figures you want to use.&lt;br /&gt;
# Add some &#039;&#039;&#039;feedback&#039;&#039;&#039; which the student will see if they enter this answer.&lt;br /&gt;
# You can specify as many answer formulae as you like - click &amp;quot;Add another answer blank&amp;quot; to add more.&lt;br /&gt;
# You can also specify units for the answers. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. If you add more than one unit, you can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
# Finally (!) you can click &amp;quot;Next page&amp;quot; to save what you&#039;ve done and move on. If you are editing an existing question, you can click &amp;quot;Next page (new question)&amp;quot; to create a completely new question based on an existing one.&lt;br /&gt;
&lt;br /&gt;
==== Penalty factor ====&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
===Tolerance===&lt;br /&gt;
&lt;br /&gt;
As for numerical questions it is possible to allow a margin within which all responses are accepted as correct. The &amp;quot;Tolerance&amp;quot; field is used for this. However, there are three different types of tolerances. These are Relative, Nominal and Geometric. If we say that the correct answer at quiz time is calculated to 200 and the tolerance is set to 0.5 then the different tolerance types work like this:&lt;br /&gt;
&lt;br /&gt;
Relative: A tolerance interval is calculated by multiplying the correct answer with 0.5, ie in this case we get 100 so for this tolerance the correct response must be between 100 and 300. (200 ± 100)&lt;br /&gt;
This is useful if the magnitude of the correct answer can differ greatly between different wildcard values.&lt;br /&gt;
&lt;br /&gt;
Nominal: This is the simplest tolerance type but not very powerful. The correct response must be between 199.5 and 200.5 (200 ± 0.5)&lt;br /&gt;
This tolerance type can be useful if the differences between different correct answers are small.&lt;br /&gt;
&lt;br /&gt;
Geometric: The upper limit of the tolerance interval is calculated as 200 + 0.5*200 and is the same as for the relative case. The lower limit is calculated as 200/(1 + 0.5). The correct response must then be between 133.33 and 300.&lt;br /&gt;
This is useful for complex calculation that must have great tolerances where relative tolerances of 1 or more would be used for the upper limit but clearly not acceptable for the lower limit as it would make zero a correct answer for all cases.&lt;br /&gt;
&lt;br /&gt;
The field Significant Figures does only relate to how the correct answer should be presented in the review or the reports. Examples: If it is set to 3 then the correct answer 13.333 would be presented as 13.3; 1236 would be presented as 1240; 23 would be presented as 23.0 etc. &lt;br /&gt;
&lt;br /&gt;
===Page 2. Choose dataset properties ===&lt;br /&gt;
&lt;br /&gt;
Each wildcard that you specify in the answer formula must have an associated set of possible values - this is its &#039;&#039;dataset&#039;&#039;. Each of the wildcards is listed on this page along with a choice of dataset:&lt;br /&gt;
*&#039;&#039;&#039;private&#039;&#039;&#039; i.e. only used by this question&lt;br /&gt;
*&#039;&#039;&#039;shared&#039;&#039;&#039; i.e shared with other calculated questions in the same category&lt;br /&gt;
&lt;br /&gt;
Using a shared dataset can save time when you are creating a lot of similar calculated questions.&lt;br /&gt;
&lt;br /&gt;
Note that even when creating a question for the first time, this page may say that your wildcard &amp;quot;will use the same existing private dataset as before.&amp;quot; This just means that Moodle has already tentatively created a private data set for that wildcard: if a private dataset is what you want, leave this choice selected.&lt;br /&gt;
&lt;br /&gt;
If there is anything in the question text that looks like a wildcard, but does not appear in any of the answer formulae, you can specify whether or not this is meant to be a wildcard. If it is, you can choose whether it should use a private or shared dataset.&lt;br /&gt;
&lt;br /&gt;
To continue, simply choose your preferred dataset for each wildcard, then click &amp;quot;Next Page&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Page 3. Edit the datasets ===&lt;br /&gt;
&lt;br /&gt;
Now we need to create the set of possible values that each wildcard can take. &#039;&#039;Warning&#039;&#039; - this page is a bit confusing!&lt;br /&gt;
&lt;br /&gt;
There are two ways of creating values - you can type them in yourself and add them to the list, or you can have Moodle generate them for you.&lt;br /&gt;
&lt;br /&gt;
==== Adding/deleting your own values ====&lt;br /&gt;
&lt;br /&gt;
Adding individual values to the list is easy:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Param&#039; field for each wildcard, enter the value you want&lt;br /&gt;
# Scroll down to the &#039;Add&#039; section and click the Add button (leaving the number of items set to 1)&lt;br /&gt;
# Repeat the above steps as many times as necessary (the maximum number of items is 100)&lt;br /&gt;
&lt;br /&gt;
To delete values from the list:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Delete&#039; section, select the number of items to delete&lt;br /&gt;
# Click the Delete button&lt;br /&gt;
&lt;br /&gt;
==== Letting Moodle create values ====&lt;br /&gt;
&lt;br /&gt;
# Start with the &amp;quot;Range of Values&amp;quot; fields, and enter the lower and upper limits for the values you would accept&lt;br /&gt;
# Choose a number of decimal places for the value&lt;br /&gt;
# Choose the distribution of values between the limits - &#039;uniform&#039; means any value between the limits is equally likely to be generated; &#039;loguniform&#039; means that values towards the lower limit are more likely.&lt;br /&gt;
# Now move down to the &#039;Add&#039; section and click on &amp;quot;force regeneration&amp;quot;&lt;br /&gt;
# In the menu next to the Add button, choose the number of sets of random values (items) you wish to add to the list. (Note that the maximum total number of items in your list is 100.)&lt;br /&gt;
# Finally, click Add to append the new values to the list&lt;br /&gt;
# &#039;&#039;&#039;Note:&#039;&#039;&#039; If you want more control over the items that Moodle adds, you can do them one at a time and preview the values before you add them. Click the &amp;quot;Get New Item to Add&amp;quot; button to make Moodle generate new values in the &amp;quot;Item to Add&amp;quot; section at the top. If you like them, click &amp;quot;Add&amp;quot; for 1 item; if not, click &amp;quot;Get New Item to Add&amp;quot; again to get new values.&lt;br /&gt;
&lt;br /&gt;
==== Finishing off ====&lt;br /&gt;
&lt;br /&gt;
Once your list of items (values) is complete, you are finished. It&#039;s up to you how many values you add - the more values you add, the more a question can be used by the students without them seeing the same values repeatedly.&lt;br /&gt;
&lt;br /&gt;
Note that if you delete values from the list, you can put them back again. Change the &amp;quot;Next Item to Add&amp;quot; option to &amp;quot;reuse previous value if available&amp;quot;, then the next time you add items, Moodle will restore your previously-deleted items from the dataset. &lt;br /&gt;
&lt;br /&gt;
Once your list of values is complete, you can click &#039;Save changes&#039; to finish.&lt;br /&gt;
&lt;br /&gt;
==== What does the &#039;Update the datasets parameters&#039; button do? ====&lt;br /&gt;
&lt;br /&gt;
Warning: This button can affect several questions, so be careful before using it.&lt;br /&gt;
Assume you have selected dataset parameter for {a} to be any value between 1-10 and generated a question. In the second question also you decide to use a SHARED wildcard called {a}. Inherently, it will show a value between 1-10. However, your need here changes and you want to make it 11-100 instead. Then, you change them in the range and click this button. Voila! the values change and you can add new items here using the &#039;Get New item to add&#039;. However, if you go back to your previous question, you will see that values would change there too, because it is a shared dataset. If you do not update parameters, then this may not happen and will generate a new set of values and displays them in the &amp;quot;Item to Add&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
==Correct answer formula syntax==&lt;br /&gt;
 &lt;br /&gt;
=== DO NOT PUT THE = sign in the formula. ===&lt;br /&gt;
 &lt;br /&gt;
* In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.&lt;br /&gt;
 If more than one correct answer formula input field are displayed when editing, &lt;br /&gt;
 your site has the multiple answer feature. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As a general rule, write these formulas like you would in a calculator e.g. &amp;lt;code&amp;gt;3 + 5 * sin(3/{x})&amp;lt;/code&amp;gt; A notable exception is exponentiation, where x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; cannot be entered as &amp;lt;code&amp;gt;{x}^3&amp;lt;/code&amp;gt;, but instead should be entered as &amp;lt;code&amp;gt;pow({x}, 3)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Each function&#039;s placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter &amp;lt;code&amp;gt;sin({a}) + cos({b}*2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* It&#039;s usually better to have too many parentheses (brackets) than too few.  The server won&#039;t care, and the more specific you are about what you mean, the more likely it will like your complex formulas.&lt;br /&gt;
* There is no implicit multiplication.  To you, the human editor, &amp;quot;5(23)&amp;quot; or &amp;quot;5x&amp;quot; may seem perfectly obvious.  To the server doing the math, it&#039;s crazy talk and won&#039;t be understood.  Always use the &amp;quot;*&amp;quot; for multiplication.&lt;br /&gt;
* Any special mathematical function must have parentheses around its values.  Take the sine function in the first bullet point for instance.  Notice that the &#039;&#039;3 / x&#039;&#039; is wrapped in parentheses (brackets)--this is so the server can understand it properly.  Without those parentheses, the server won&#039;t know if you mean &amp;quot;(sin 3) / x&amp;quot; or &amp;quot;sin (3 / x)&amp;quot; and will reject the entire formula accordingly.&lt;br /&gt;
&lt;br /&gt;
==Available functions==&lt;br /&gt;
&lt;br /&gt;
Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;97%&amp;quot; border=&amp;quot;1px&amp;quot;&lt;br /&gt;
!Function&lt;br /&gt;
!Explanation&lt;br /&gt;
|-&lt;br /&gt;
|abs&lt;br /&gt;
|Absolute value&lt;br /&gt;
|-&lt;br /&gt;
|acos&lt;br /&gt;
|Arc cosine -- output in radians.&lt;br /&gt;
|-&lt;br /&gt;
|acosh&lt;br /&gt;
|Inverse hyperbolic cosine -- output in radians.&lt;br /&gt;
|-&lt;br /&gt;
|asin&lt;br /&gt;
|Arc sine -- output in radians.&lt;br /&gt;
|-&lt;br /&gt;
|asinh&lt;br /&gt;
|Inverse hyperbolic sine.-- output in radians.&lt;br /&gt;
|-&lt;br /&gt;
|atan2&lt;br /&gt;
|Arc tangent of two variables -- pass in two values like (y, x), and you&#039;ll get the atah(y/x), adjusted to the proper quadrant. (Note: The variables are in the reverse order to atan2(x,y) in Excel) Output is radians.&lt;br /&gt;
|-&lt;br /&gt;
|atan&lt;br /&gt;
|Arc tangent -- output in radians.   &lt;br /&gt;
|-&lt;br /&gt;
|atanh&lt;br /&gt;
|Inverse hyperbolic tangent-- output in radians.&lt;br /&gt;
|-&lt;br /&gt;
|bindec&lt;br /&gt;
|Binary to decimal&lt;br /&gt;
|-&lt;br /&gt;
|ceil&lt;br /&gt;
|Round fractions up&lt;br /&gt;
|-&lt;br /&gt;
|cos&lt;br /&gt;
|Cosine -- in radians!!!  Convert your degree measurement to radians before you take the cos of it.&lt;br /&gt;
|-&lt;br /&gt;
|cosh&lt;br /&gt;
|Hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the cosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|decbin&lt;br /&gt;
|Decimal to binary&lt;br /&gt;
|-&lt;br /&gt;
|decoct&lt;br /&gt;
|Decimal to octal&lt;br /&gt;
|-&lt;br /&gt;
|deg2rad&lt;br /&gt;
|Converts the number in degrees to the radian equivalent&lt;br /&gt;
|-&lt;br /&gt;
|exp&lt;br /&gt;
|Calculates the exponent of e&lt;br /&gt;
|-&lt;br /&gt;
|expm1&lt;br /&gt;
|Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|floor&lt;br /&gt;
|Round fractions down&lt;br /&gt;
|-&lt;br /&gt;
|fmod&lt;br /&gt;
|Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.&lt;br /&gt;
|-&lt;br /&gt;
|is_finite&lt;br /&gt;
|Finds whether a value is a legal finite number&lt;br /&gt;
|-&lt;br /&gt;
|is_infinite&lt;br /&gt;
|Finds whether a value is infinite&lt;br /&gt;
|-&lt;br /&gt;
|is_nan&lt;br /&gt;
|Finds whether a value is not a number&lt;br /&gt;
|-&lt;br /&gt;
|log10&lt;br /&gt;
|Base-10 logarithm&lt;br /&gt;
|-&lt;br /&gt;
|log1p&lt;br /&gt;
|Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|log&lt;br /&gt;
|Natural logarithm (&#039;&#039;ln&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|Find highest value&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|Find lowest value&lt;br /&gt;
|-&lt;br /&gt;
|octdec&lt;br /&gt;
|Octal to decimal&lt;br /&gt;
|-&lt;br /&gt;
|pi()&lt;br /&gt;
|Get value of pi - the function does not take an argument, like in Excel.&lt;br /&gt;
|-&lt;br /&gt;
|pow (numberToRaise, NumberRaisedTo)&lt;br /&gt;
|Exponential expression&lt;br /&gt;
|-&lt;br /&gt;
|rad2deg&lt;br /&gt;
|Converts the radian number to the equivalent number in degrees&lt;br /&gt;
|-&lt;br /&gt;
|rand&lt;br /&gt;
|Generate a random integer&lt;br /&gt;
|-&lt;br /&gt;
|round&lt;br /&gt;
|Rounds a float&lt;br /&gt;
|-&lt;br /&gt;
|sin&lt;br /&gt;
|Sine -- in radians!!!  Convert your degree measurement to radians before you take the sin of it.&lt;br /&gt;
|-&lt;br /&gt;
|sinh&lt;br /&gt;
|Hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the sinh of it.&lt;br /&gt;
|-&lt;br /&gt;
|sqrt&lt;br /&gt;
|Square root&lt;br /&gt;
|-&lt;br /&gt;
|tan&lt;br /&gt;
|Tangent -- in radians!!!  Convert your degree measurement to radians before you take the tan of it.&lt;br /&gt;
|-&lt;br /&gt;
|tanh&lt;br /&gt;
|Hyperbolic tangent -- in radians!!!  Convert your degree measurement to radians before you take the tanh of it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Predefined constants==&lt;br /&gt;
Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.&lt;br /&gt;
&lt;br /&gt;
==Synchronization==&lt;br /&gt;
&lt;br /&gt;
You could use shared wild cards to get the same values across questions in a quiz.&lt;br /&gt;
&lt;br /&gt;
A simple example will be to use the same radius in a first question asking for the perimiter of a circle of {radius}cm and a second question asking for the surface of a circle of {radius}cm.&lt;br /&gt;
&lt;br /&gt;
When the quiz will be shown to the student the two questions will shown the same {radius} value.&lt;br /&gt;
&lt;br /&gt;
However the synchronization will work &#039;&#039;&#039;ONLY&#039;&#039;&#039; if the questions are kept in the &#039;&#039;&#039;SAME&#039;&#039;&#039; category and have the &#039;&#039;&#039;SAME NUMBER OF DATASETS&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
If you need to move the synchronized questions to another category, you need to do it by editing the questions.&lt;br /&gt;
&lt;br /&gt;
(This restriction should be released by sept. 2010).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=150923 couple questions about &amp;quot;edit datasets page&amp;quot; in calculated questions] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
&lt;br /&gt;
[[de:Berechnungsfragen]]&lt;br /&gt;
[[fr:Question calculée]]&lt;br /&gt;
[[zh:計算題]]&lt;br /&gt;
[[ja:計算問題タイプ]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83235</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83235"/>
		<updated>2011-05-05T11:49:33Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to an initial quiz forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put your comments on the forum.&lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=174387&lt;br /&gt;
&lt;br /&gt;
See also http://tracker.moodle.org/browse/MDL-27363&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer numerical format as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list of available formats we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree,  minute, second &lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
===Feasability of adding number format as an additional numerical answer table ===&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvement could wait after 2,1 release.&lt;br /&gt;
&lt;br /&gt;
===The actual code does not detect number format===&lt;br /&gt;
&lt;br /&gt;
The historical objective in the apply_unit() was to convert various number formats so that they comply to the PHP norm for a number.&lt;br /&gt;
&lt;br /&gt;
The most current thousand separators( i.e space and ,) are filtered out.&lt;br /&gt;
&lt;br /&gt;
In 2,0 the , as unit separator is replaced by . &lt;br /&gt;
&lt;br /&gt;
In all cases PHP numerical format is valid i.e. 123456.78 or 1.2345678e5&lt;br /&gt;
&lt;br /&gt;
A clever student will never use thousand separators and will learn once for all if he can use , or . as unit separator.&lt;br /&gt;
&lt;br /&gt;
Shortanswer is a better way to test for number formats...&lt;br /&gt;
&lt;br /&gt;
===Implementing a number format analysis===&lt;br /&gt;
&lt;br /&gt;
to do ...&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:13, 2 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83180</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83180"/>
		<updated>2011-05-02T14:21:12Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* The actual code does not detect number format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to an initial quiz forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put your comments on the forum.&lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=174387&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer numerical format as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list of available formats we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree,  minute, second &lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
===Feasability of adding number format as an additional numerical answer table ===&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvement could wait after 2,1 release.&lt;br /&gt;
&lt;br /&gt;
===The actual code does not detect number format===&lt;br /&gt;
&lt;br /&gt;
The historical objective in the apply_unit() was to convert various number formats so that they comply to the PHP norm for a number.&lt;br /&gt;
&lt;br /&gt;
The most current thousand separators( i.e space and ,) are filtered out.&lt;br /&gt;
&lt;br /&gt;
In 2,0 the , as unit separator is replaced by . &lt;br /&gt;
&lt;br /&gt;
In all cases PHP numerical format is valid i.e. 123456.78 or 1.2345678e5&lt;br /&gt;
&lt;br /&gt;
A clever student will never use thousand separators and will learn once for all if he can use , or . as unit separator.&lt;br /&gt;
&lt;br /&gt;
Shortanswer is a better way to test for number formats...&lt;br /&gt;
&lt;br /&gt;
===Implementing a number format analysis===&lt;br /&gt;
&lt;br /&gt;
to do ...&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:13, 2 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83179</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83179"/>
		<updated>2011-05-02T14:19:34Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* The actual code does not detect number format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to an initial quiz forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put your comments on the forum.&lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=174387&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer numerical format as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list of available formats we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree,  minute, second &lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
===Feasability of adding number format as an additional numerical answer table ===&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvement could wait after 2,1 release.&lt;br /&gt;
&lt;br /&gt;
===The actual code does not detect number format===&lt;br /&gt;
&lt;br /&gt;
The historical objective in the apply_unit() was to convert various number formats so that they comply to the PHP norm for a number.&lt;br /&gt;
&lt;br /&gt;
The most current thousand separators( i.e space and ,) are filtered out.&lt;br /&gt;
in 2,0 the , as unit separator is replace by a . &lt;br /&gt;
&lt;br /&gt;
In all cases PHP numerical format is valid i.e. 123456.78 or 1.2345678e5&lt;br /&gt;
&lt;br /&gt;
A clever student will never use thousand separators and will learn once for all if he can use , or . as unit separator.&lt;br /&gt;
&lt;br /&gt;
Shortanswer is a better way to test for number formats...&lt;br /&gt;
&lt;br /&gt;
===Implementing a number format analysis===&lt;br /&gt;
&lt;br /&gt;
to do ...&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:13, 2 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83178</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83178"/>
		<updated>2011-05-02T14:13:21Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Designing a number format penalty */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to an initial quiz forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put your comments on the forum.&lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=174387&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer numerical format as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list of available formats we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree,  minute, second &lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
===Feasability of adding number format as an additional numerical answer table ===&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvement could wait after 2,1 release.&lt;br /&gt;
&lt;br /&gt;
===The actual code does not detect number format===&lt;br /&gt;
&lt;br /&gt;
The historical objective in the apply_unit() was to convert various number formats so that they comply to the PHP norm for a number.&lt;br /&gt;
The most current thousand separators( i.e space and ,) are filtered out.&lt;br /&gt;
in 2,0 the , as unit separator is replace by a . &lt;br /&gt;
In all cases PHP numerical format is valid i.e. 123456.78 or 1.2345678e5 &lt;br /&gt;
&lt;br /&gt;
===Implementing a number format analysis===&lt;br /&gt;
&lt;br /&gt;
to do ...&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:13, 2 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83160</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83160"/>
		<updated>2011-05-02T02:37:47Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Designing a number format penalty */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to an initial quiz forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put your comments on the forum.&lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=174387&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer numerical format as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list of available formats we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree,  minute, second &lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvement could wait after 2,1 release.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 to be continued...&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:06, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83159</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83159"/>
		<updated>2011-05-01T15:27:12Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to an initial quiz forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put your comments on the forum.&lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=174387&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree,  minute, second &lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvement could wait after 2,1 release.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 to be continued...&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:06, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83158</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83158"/>
		<updated>2011-05-01T15:25:30Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Designing a number format penalty */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put comments on the forum.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree,  minute, second &lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvement could wait after 2,1 release.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 to be continued...&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:06, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83157</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83157"/>
		<updated>2011-05-01T15:24:08Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Designing a number format penalty */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put comments on the forum.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree,  minute, second &lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvment could wait after 2,1 release.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 to be continued...&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:06, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83156</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83156"/>
		<updated>2011-05-01T15:09:09Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Designing a number format penalty */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put comments on the forum.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree, second, minutes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The answer field being set as TEXT can easily store a numerical value in any format that can be validated easily in  edit_numerical_form.php and the &lt;br /&gt;
 &amp;lt;code php&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Get an answer that contains the feedback and fraction that should be&lt;br /&gt;
     * awarded for this resonse.&lt;br /&gt;
     * @param number $value the numerical value of a response.&lt;br /&gt;
     * @return question_answer the matching answer.&lt;br /&gt;
     */&lt;br /&gt;
    public function get_matching_answer($value) {&lt;br /&gt;
        foreach ($this-&amp;gt;answers as $aid =&amp;gt; $answer) {&lt;br /&gt;
            if ($answer-&amp;gt;within_tolerance($value)) {&lt;br /&gt;
                $answer-&amp;gt;id = $aid;&lt;br /&gt;
                return $answer;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
modified accordingly.&lt;br /&gt;
&lt;br /&gt;
If the 2,1 new engine initial code uses an equivalent to the Moodle 2,0 apply_unit() function, this improvment could wait after 2,1 release.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 to be continued...&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:06, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83155</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83155"/>
		<updated>2011-05-01T14:14:14Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
Please put comments on the forum.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree, second, minutes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 to be continued...&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:06, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83154</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83154"/>
		<updated>2011-05-01T14:06:17Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Numerical question grading ==&lt;br /&gt;
&lt;br /&gt;
There are 3 elements that can be graded in a numerical question&lt;br /&gt;
# the numeric value&lt;br /&gt;
# the unit used in relation to the numeric value&lt;br /&gt;
# the number format used to express the value&lt;br /&gt;
&lt;br /&gt;
1 and 2 are addressed in Moodle 2,0 for questions created from edit_numerical_form.php.&lt;br /&gt;
 &lt;br /&gt;
3 can give a 0 grade if the student does not use one of the number formats allowed but there is no specific grading designed as the unit penalty since Moodle 2,0.&lt;br /&gt;
&lt;br /&gt;
==Designing a number format penalty==&lt;br /&gt;
&lt;br /&gt;
We have already 2 ways to grade the student response available in the edit_numerical_form.php. i.e. &lt;br /&gt;
* the answer-tolerance combination&lt;br /&gt;
* the detailed unit grading &lt;br /&gt;
&lt;br /&gt;
We need flexibility to take in account that number format can vary even at a same location i.e. in Canada there are two locales as there are two official languages (french and english).&lt;br /&gt;
&lt;br /&gt;
Teacher sometimes ask for specific number formats as fraction that cannot be allowed simultanuously to other grading.&lt;br /&gt;
&lt;br /&gt;
The most universal solution is to associate a grade to a specific answer as the tolerance is used.&lt;br /&gt;
&lt;br /&gt;
For example in calculated the tolerance can be set as relative or absolute.&lt;br /&gt;
&lt;br /&gt;
So my proposal is to add the number format as a new answer parameter.&lt;br /&gt;
&lt;br /&gt;
To an official locales list we could add &lt;br /&gt;
* specific Moodle formats as the one used for 1,9 2,0 , &lt;br /&gt;
* a fraction format, &lt;br /&gt;
* time format, &lt;br /&gt;
* degree, second, minutes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 22:06, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83153</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83153"/>
		<updated>2011-05-01T13:24:11Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Grading the numerical format used by the student to express the numerical value */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 21:24, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83152</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83152"/>
		<updated>2011-05-01T13:23:50Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Retrieving the numerical value from the student response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
As the  function apply_unit()  is also used to analyze the student response the number formats allowed are the same as the formats allowed for NON edit_numerical_form.php numerical i.e. import or Cloze.&lt;br /&gt;
&lt;br /&gt;
However to help students know what are the number formats allowed an help icon aside the number text input element is shown on Moodle 2,0 numerical  questions created either by edit_numerical_form.php or import but not for Cloze.&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 11:00, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83151</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83151"/>
		<updated>2011-05-01T13:12:08Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Setting the answer when creating the question */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 11:00, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83145</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83145"/>
		<updated>2011-05-01T03:22:14Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Setting the answer when creating the question */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
The 2,0 apply_unit allows more number formats than the test in the editing form. &lt;br /&gt;
&lt;br /&gt;
* regular numbers  13500.67 : 13 500.67 : 13500,67: 13 500,67&lt;br /&gt;
&lt;br /&gt;
* if you use , as thousand separator *always* put the decimal . as in &lt;br /&gt;
 13,500.67 : 13,500.&lt;br /&gt;
 &lt;br /&gt;
* for exponent form, say 1.350067 * 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;, use  &lt;br /&gt;
 1.350067 E4 : 1.350067 E04 &#039;;&lt;br /&gt;
The 1,9 apply_unit is more restrictive as it does not support , as decimal separator.&lt;br /&gt;
&lt;br /&gt;
More formats were allowed in 2,0 as the main objective in a numerical question is the numerical value.&lt;br /&gt;
More about this further in the page (todo)&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 11:00, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83144</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83144"/>
		<updated>2011-05-01T03:08:35Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Setting the answer when creating the question */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
the Moodle 2,0 apply_unit&lt;br /&gt;
   &amp;lt;code php&amp;gt; &lt;br /&gt;
    /**&lt;br /&gt;
     * Checks if the $rawresponse has a unit and applys it if appropriate.&lt;br /&gt;
     *&lt;br /&gt;
     * @param string $rawresponse  The response string to be converted to a float.&lt;br /&gt;
     * @param array $units         An array with the defined units, where the&lt;br /&gt;
     *                             unit is the key and the multiplier the value.&lt;br /&gt;
     * @return float               The rawresponse with the unit taken into&lt;br /&gt;
     *                             account as a float.&lt;br /&gt;
     */&lt;br /&gt;
    function apply_unit($rawresponse, $units) {&lt;br /&gt;
&lt;br /&gt;
        // Make units more useful&lt;br /&gt;
        $tmpunits = array();&lt;br /&gt;
        foreach ($units as $unit) {&lt;br /&gt;
            $tmpunits[$unit-&amp;gt;unit] = $unit-&amp;gt;multiplier;&lt;br /&gt;
        }&lt;br /&gt;
        // remove spaces and normalise decimal places.&lt;br /&gt;
        $rawresponse = trim($rawresponse) ;&lt;br /&gt;
        $search  = array(&#039; &#039;, &#039;,&#039;);&lt;br /&gt;
        // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don&#039;t need spaces and ,&lt;br /&gt;
        if ( strpos($rawresponse,&#039;.&#039; ) !== false || substr_count($rawresponse,&#039;,&#039;) &amp;gt; 1 ) {&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;&#039;);&lt;br /&gt;
        }else { // remove spaces and normalise , to a . .&lt;br /&gt;
            $replace = array(&#039;&#039;, &#039;.&#039;);&lt;br /&gt;
        }&lt;br /&gt;
        $rawresponse = str_replace($search, $replace, $rawresponse);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        // Apply any unit that is present.&lt;br /&gt;
        if (ereg(&#039;^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$&#039;,&lt;br /&gt;
                $rawresponse, $responseparts)) {&lt;br /&gt;
                echo&amp;quot;&amp;lt;p&amp;gt; responseparts &amp;lt;pre&amp;gt;&amp;quot;;print_r($responseparts) ;echo&amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if (!empty($responseparts[5])) {&lt;br /&gt;
&lt;br /&gt;
                if (isset($tmpunits[$responseparts[5]])) {&lt;br /&gt;
                    // Valid number with unit.&lt;br /&gt;
                    return (float)$responseparts[1] / $tmpunits[$responseparts[5]];&lt;br /&gt;
                } else {&lt;br /&gt;
                    // Valid number with invalid unit. Must be wrong.&lt;br /&gt;
                    return false;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
            } else {&lt;br /&gt;
                // Valid number without unit.&lt;br /&gt;
                return (float)$responseparts[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Invalid number. Must be wrong.&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 11:00, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83143</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83143"/>
		<updated>2011-05-01T03:00:27Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Grading the numerical format used by the student to express the numerical value */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 11:00, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83142</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83142"/>
		<updated>2011-05-01T03:00:03Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Setting the answer when creating the question */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1,9 and 2,0 in the edit_numerical_form.php, the number enter by the teacher (although student could be allowed to create question, I will use teacher for text clarity) must be conform to the PHP syntax (no thousand separator or space and . as decimal separator. E syntax is allowed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code php&amp;gt;                if (!(is_numeric($trimmedanswer) || $trimmedanswer == &#039;*&#039;)) {&lt;br /&gt;
                    $errors[&#039;answer[&#039; . $key . &#039;]&#039;] =&lt;br /&gt;
                            get_string(&#039;answermustbenumberorstar&#039;, &#039;qtype_numerical&#039;);&lt;br /&gt;
                }&lt;br /&gt;
 &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the teacher must know the PHP specific number syntax.&lt;br /&gt;
&lt;br /&gt;
In the  numerical/questiontype.php    function save_question_options($question) &lt;br /&gt;
there is an additional verification mostly for numerical questions imported through various formats or inside a Cloze numerical multianswer question.&lt;br /&gt;
    &amp;lt;code php&amp;gt;         &lt;br /&gt;
                $answer-&amp;gt;answer = $this-&amp;gt;apply_unit($answerdata, $units);&lt;br /&gt;
                if ($answer-&amp;gt;answer === false) {&lt;br /&gt;
                    $result-&amp;gt;notice = get_string(&#039;invalidnumericanswer&#039;, &#039;quiz&#039;);&lt;br /&gt;
                }&lt;br /&gt;
    &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 07:39, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83141</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83141"/>
		<updated>2011-04-30T23:50:31Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
http://moodle.org/mod/forum/discuss.php?d=172211#p755927&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 07:39, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83140</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83140"/>
		<updated>2011-04-30T23:48:56Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Numbers as written by human and readed by computer language */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts (number and exponent).&lt;br /&gt;
 1.2345678+E05 will be a structure that is well recognized by a computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
==Setting the answer when creating the question==&lt;br /&gt;
&lt;br /&gt;
==Retrieving the numerical value from the student response==&lt;br /&gt;
&lt;br /&gt;
==Grading the numerical format used by the student to express the numerical value ==&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 07:39, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83139</id>
		<title>Development:Question Engine 2:Numerical formats</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Question_Engine_2:Numerical_formats&amp;diff=83139"/>
		<updated>2011-04-30T23:39:46Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: Created page with &amp;quot;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated). This page describes a possible implementation and ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Question Engine 2 structure allows implementation of new features for numerical question types ( numerical and calculated).&lt;br /&gt;
This page describes a possible implementation and its rationale.&lt;br /&gt;
&lt;br /&gt;
The text should be readed as a personal summary of the work in progress and not as a textbook on computer language and real numbers representation.&lt;br /&gt;
&lt;br /&gt;
It is related to the forum discussion &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Numbers as written by human and readed by computer language== &lt;br /&gt;
&lt;br /&gt;
The main feature of numerical question type is to ask the student to give a numerical answer i.e. a number.&lt;br /&gt;
Most often this means a numerical value that is not an integer ( dates are a current example of integer value response) but a real number which value is expressed most often as a decimal number i.e 1.234 .&lt;br /&gt;
&lt;br /&gt;
Computer languages ( i.e PHP used in Moodle) store real numbers in a different way than human do (decimal part and exponent similar to 1.234 E00) and humans do not expressed real nmumbers in an universal format.&lt;br /&gt;
&lt;br /&gt;
 The separator between the unit and the decimal fraction is often either a . or a ,  &lt;br /&gt;
 1.234   1,234&lt;br /&gt;
&lt;br /&gt;
Furthermore to help reading large numbers, most language add another separator for thousands often space or , if it is not used already as unit separator.&lt;br /&gt;
 123 456.78     123,456.78   123 456,78 &lt;br /&gt;
&lt;br /&gt;
PHP as a computer language use space to separate the language components so cannot use space as a thousand separator.&lt;br /&gt;
&lt;br /&gt;
, is also used to separate variables so PHP use a simpler syntax 123456.78.&lt;br /&gt;
&lt;br /&gt;
As this is stored in the computer as 2 parts 1.2345678+E05 will be a structure that is well recognized by computer language as PHP.&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 07:39, 1 May 2011 (WST)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:Numerical_question_type&amp;diff=83138</id>
		<title>Development:Numerical question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:Numerical_question_type&amp;diff=83138"/>
		<updated>2011-04-30T22:52:25Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* State-&amp;gt;options */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questiontype developer docs}}&lt;br /&gt;
&lt;br /&gt;
==Database tables==&lt;br /&gt;
&lt;br /&gt;
===quiz_numerical===&lt;br /&gt;
&lt;br /&gt;
The quiz_numerical table is an extension of the quiz_answers table, defining a tolerance value for each answer.&lt;br /&gt;
&lt;br /&gt;
;id :int(10) unsigned NOT NULL auto_increment,&lt;br /&gt;
;question :int(10) unsigned NOT NULL default &#039;0&#039;,&lt;br /&gt;
;answer :int(10) unsigned NOT NULL default &#039;0&#039;,&lt;br /&gt;
;tolerance :varchar(255) NOT NULL default &#039;0.0&#039;,&lt;br /&gt;
&lt;br /&gt;
===quiz_numerical_units===&lt;br /&gt;
&lt;br /&gt;
The quiz_numerical_units table is used by the numerical questiontype and the calculated questionype. It extends the quiz_questions table, defining an arbitrary number of units that can be used in the responses.&lt;br /&gt;
&lt;br /&gt;
;id :int(10) unsigned NOT NULL auto_increment,&lt;br /&gt;
;question :int(10) unsigned NOT NULL default &#039;0&#039;,&lt;br /&gt;
;multiplier :decimal(40,20) NOT NULL default &#039;1.00000000000000000000&#039;,&lt;br /&gt;
;unit :varchar(50) NOT NULL default &#039;&#039;,&lt;br /&gt;
&lt;br /&gt;
==Response storage==&lt;br /&gt;
&lt;br /&gt;
The numerical questiontype, which inherits the function print_question_formulation_and_controls() from the shortanswer questiontype, has only one response field, so its responses are handled by the default questiontype. The response is stored without any modifications in the answer field of the table quiz_states.&lt;br /&gt;
&lt;br /&gt;
==Question-&amp;gt;options==&lt;br /&gt;
&lt;br /&gt;
==State-&amp;gt;options==&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Numerical question type]]&lt;br /&gt;
[[Category:Quiz]]&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
[[Development:Question Engine 2:Numerical formats |Numerical formats]], gives a proposal for implementing various numerical formats for numerical and calculated question type in Question Engine 2.1.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=78295</id>
		<title>Calculated question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=78295"/>
		<updated>2010-11-26T01:12:50Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
Calculated questions offer a way to create individual numerical questions by the use of wildcards  (i.e &#039;&#039;&#039;{x}&#039;&#039;&#039; , &#039;&#039;&#039;{y}&#039;&#039;&#039;) that are substituted with random values when the quiz is taken.&lt;br /&gt;
 &lt;br /&gt;
For example, if you want to create a large number of &#039;&#039;&#039;&amp;quot;Calculate the area of a rectangle&amp;quot;&#039;&#039;&#039; problems to drill your students, you could create a question with two wildcards (i.e. &#039;&#039;&#039;{base}&#039;&#039;&#039;, &#039;&#039;&#039;{height}&#039;&#039;&#039;) and put in the &amp;quot;&#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039;&amp;quot; input field  &#039;&#039;&#039;{base}&#039;&#039;&#039; * &#039;&#039;&#039;{height}&#039;&#039;&#039; ( * being the multiplication sign ).&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039; {base}*{height}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
When a student takes the test, Moodle will randomly select values for &#039;&#039;&#039;{base}&#039;&#039;&#039; and &#039;&#039;&#039;{height}&#039;&#039;&#039; and grade the response using the result of the &#039;&#039;&#039;Correct Answer Formula&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The test will very rarely appear the same way twice.&lt;br /&gt;
&lt;br /&gt;
== Is this really the question type for you? ==&lt;br /&gt;
The main purpose of the calculated question is to create multiple versions of a question with different numerical values. This means you must have &#039;&#039;&#039;at least one&#039;&#039;&#039; wildcard in one of the answers.&lt;br /&gt;
 &lt;br /&gt;
If you don&#039;t need a random element, use the [[Numerical question type]] instead.&lt;br /&gt;
== Simple calculated question type   ==&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
The [[Simple calculated question type|simple calculated]] question offers the most used features of the calculated question with a much simpler creation interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Wildcards and datasets==&lt;br /&gt;
&lt;br /&gt;
When Moodle delivers a Calculated question to the student, the wildcards are replaced with randomly-selected values. However, these values are not completely random - rather, they are randomly selected from a pre-defined &#039;&#039;dataset&#039;&#039; of possible values. This allows you some control over the possible values chosen - for example, in order to make sure the numbers are realistic.&lt;br /&gt;
&lt;br /&gt;
These datasets can be &#039;&#039;private&#039;&#039; or &#039;&#039;shared&#039;&#039; - private datasets are used by one wildcard within one calculated question; shared datasets are used by one wildcard within all calculated questions that use it.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
To create (or modify) a calculated question there are three pages to work through. The instructions below take you through the pages, step by step:&lt;br /&gt;
&lt;br /&gt;
===Page 1. Editing a Calculated question ===&lt;br /&gt;
&lt;br /&gt;
#Select the question &#039;&#039;&#039;category&#039;&#039;&#039;&lt;br /&gt;
#Any shared wildcards for this category are listed beneath. If you change category, you&#039;ll need to click the &amp;quot;Update the category&amp;quot; button to refresh this list. There may not be any shared wildcards yet - if not, you can create them later if you wish.&lt;br /&gt;
#Give the question a descriptive &#039;&#039;&#039;name&#039;&#039;&#039; - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the &#039;&#039;&#039;question text&#039;&#039;&#039;. This should be the question you want the student to answer, and it must include all the information they need to calculate an answer. Therefore it must contain at least one wildcard, inside curly braces. For example, if you wanted the student to sum numbers A and B, the question text might read: &amp;quot;What is {A} + {B}?&amp;quot;&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices. If you want more control over how the image appears, include it in the question text above, using the HTML editor.&lt;br /&gt;
#Set the &#039;&#039;&#039;default question grade&#039;&#039;&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;&#039;&#039;Penalty factor&#039;&#039;&#039; (see [[Calculated_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#&#039;&#039;Moodle 1.7+:&#039;&#039; If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Next add the &#039;&#039;&#039;formula for the answer&#039;&#039;&#039;. This formula must contain at least the wildcards that appear in the question text. See [[Calculated_question_type#Correct_answer_formula_syntax|Correct answer formula syntax]] for further details.&lt;br /&gt;
# Choose the &#039;&#039;&#039;grade&#039;&#039;&#039; that the student will get for this question if they give this answer. This should be a percentage of the total marks available. For example, you could give 100% for a correct answer, and 50% for an answer that is nearly right. &#039;&#039;&#039;One of the answers must have a 100% grade&#039;&#039;&#039;.&lt;br /&gt;
#Determine the &#039;&#039;&#039;tolerance&#039;&#039;&#039; for error that you will accept in the answer. The tolerance and tolerance type settings combine to give a range of acceptable scores. So, if tolerance = t, correct answer = x and the difference between the user&#039;s answer and the correct answer is dx, then the tolerance types are as follows:&lt;br /&gt;
##Nominal - mark correct if dx &amp;lt;= t&lt;br /&gt;
##Relative - mark correct if dx / x &amp;lt;= t&lt;br /&gt;
##Geometric - mark correct if dx² / x² &amp;lt;= t²&lt;br /&gt;
# The next 2 settings, &amp;quot;Correct answer shows&amp;quot; and &amp;quot;Format&amp;quot; determine the &#039;&#039;&#039;precision&#039;&#039;&#039; of the answer. Use these to select the number of decimal places or significant figures you want to use.&lt;br /&gt;
# Add some &#039;&#039;&#039;feedback&#039;&#039;&#039; which the student will see if they enter this answer.&lt;br /&gt;
# You can specify as many answer formulae as you like - click &amp;quot;Add another answer blank&amp;quot; to add more.&lt;br /&gt;
# You can also specify units for the answers. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. If you add more than one unit, you can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
# Finally (!) you can click &amp;quot;Next page&amp;quot; to save what you&#039;ve done and move on. If you are editing an existing question, you can click &amp;quot;Next page (new question)&amp;quot; to create a completely new question based on an existing one.&lt;br /&gt;
&lt;br /&gt;
==== Penalty factor ====&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
===Tolerance===&lt;br /&gt;
&lt;br /&gt;
As for numerical questions it is possible to allow a margin within which all responses are accepted as correct. The &amp;quot;Tolerance&amp;quot; field is used for this. However, there are three different types of tolerances. These are Relative, Nominal and Geometric. If we say that the correct answer at quiz time is calculated to 200 and the tolerance is set to 0.5 then the different tolerance types work like this:&lt;br /&gt;
&lt;br /&gt;
Relative: A tolerance interval is calculated by multiplying the correct answer with 0.5, ie in this case we get 100 so for this tolerance the correct response must be between 100 and 300. (200 ± 100)&lt;br /&gt;
This is useful if the magnitude of the correct answer can differ greatly between different wildcard values.&lt;br /&gt;
&lt;br /&gt;
Nominal: This is the simplest tolerance type but not very powerful. The correct response must be between 199.5 and 200.5 (200 ± 0.5)&lt;br /&gt;
This tolerance type can be useful if the differences between different correct answers are small.&lt;br /&gt;
&lt;br /&gt;
Geometric: The upper limit of the tolerance interval is calculated as 200 + 0.5*200 and is the same as for the relative case. The lower limit is calculated as 200/(1 + 0.5). The correct response must then be between 133.33 and 300.&lt;br /&gt;
This is useful for complex calculation that must have great tolerances where relative tolerances of 1 or more would be used for the upper limit but clearly not acceptable for the lower limit as it would make zero a correct answer for all cases.&lt;br /&gt;
&lt;br /&gt;
The field Significant Figures does only relate to how the correct answer should be presented in the review or the reports. Examples: If it is set to 3 then the correct answer 13.333 would be presented as 13.3; 1236 would be presented as 1240; 23 would be presented as 23.0 etc. &lt;br /&gt;
&lt;br /&gt;
===Page 2. Choose dataset properties ===&lt;br /&gt;
&lt;br /&gt;
Each wildcard that you specify in the answer formula must have an associated set of possible values - this is its &#039;&#039;dataset&#039;&#039;. Each of the wildcards is listed on this page along with a choice of dataset:&lt;br /&gt;
*&#039;&#039;&#039;private&#039;&#039;&#039; i.e. only used by this question&lt;br /&gt;
*&#039;&#039;&#039;shared&#039;&#039;&#039; i.e shared with other calculated questions in the same category&lt;br /&gt;
&lt;br /&gt;
Using a shared dataset can save time when you are creating a lot of similar calculated questions.&lt;br /&gt;
&lt;br /&gt;
If there is anything in the question text that looks like a wildcard, but does not appear in any of the answer formulae, you can specify whether or not this is meant to be a wildcard. If it is, you can choose whether it should use a private or shared dataset.&lt;br /&gt;
&lt;br /&gt;
To continue, simply choose your preferred dataset for each wildcard, then click &amp;quot;Next Page&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Page 3. Edit the datasets ===&lt;br /&gt;
&lt;br /&gt;
Now we need to create the set of possible values that each wildcard can take. &#039;&#039;Warning&#039;&#039; - this page is a bit confusing!&lt;br /&gt;
&lt;br /&gt;
There are two ways of creating values - you can type them in yourself and add them to the list, or you can have Moodle generate them for you.&lt;br /&gt;
&lt;br /&gt;
==== Adding/deleting your own values ====&lt;br /&gt;
&lt;br /&gt;
Adding individual values to the list is easy:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Param&#039; field for each wildcard, enter the value you want&lt;br /&gt;
# Scroll down to the &#039;Add&#039; section and click the Add button (leaving the number of items set to 1)&lt;br /&gt;
# Repeat the above steps as many times as necessary (the maximum number of items is 100)&lt;br /&gt;
&lt;br /&gt;
To delete values from the list:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Delete&#039; section, select the number of items to delete&lt;br /&gt;
# Click the Delete button&lt;br /&gt;
&lt;br /&gt;
==== Letting Moodle create values ====&lt;br /&gt;
&lt;br /&gt;
# Start with the &amp;quot;Range of Values&amp;quot; fields, and enter the lower and upper limits for the values you would accept&lt;br /&gt;
# Choose a number of decimal places for the value&lt;br /&gt;
# Choose the distribution of values between the limits - &#039;uniform&#039; means any value between the limits is equally likely to be generated; &#039;loguniform&#039; means that values towards the lower limit are more likely.&lt;br /&gt;
# Now move down to the &#039;Add&#039; section and click on &amp;quot;force regeneration&amp;quot;&lt;br /&gt;
# In the menu next to the Add button, choose the number of sets of random values (items) you wish to add to the list. (Note that the maximum total number of items in your list is 100.)&lt;br /&gt;
# Finally, click Add to append the new values to the list&lt;br /&gt;
# &#039;&#039;&#039;Note:&#039;&#039;&#039; If you want more control over the items that Moodle adds, you can do them one at a time and preview the values before you add them. Click the &amp;quot;Get New Item to Add&amp;quot; button to make Moodle generate new values in the &amp;quot;Item to Add&amp;quot; section at the top. If you like them, click &amp;quot;Add&amp;quot; for 1 item; if not, click &amp;quot;Get New Item to Add&amp;quot; again to get new values.&lt;br /&gt;
&lt;br /&gt;
==== Finishing off ====&lt;br /&gt;
&lt;br /&gt;
Once your list of items (values) is complete, you are finished. It&#039;s up to you how many values you add - the more values you add, the more a question can be used by the students without them seeing the same values repeatedly.&lt;br /&gt;
&lt;br /&gt;
Note that if you delete values from the list, you can put them back again. Change the &amp;quot;Next Item to Add&amp;quot; option to &amp;quot;reuse previous value if available&amp;quot;, then the next time you add items, Moodle will restore your previously-deleted items from the dataset. &lt;br /&gt;
&lt;br /&gt;
Once your list of values is complete, you can click &#039;Save changes&#039; to finish.&lt;br /&gt;
&lt;br /&gt;
==== What does the &#039;Update the datasets parameters&#039; button do? ====&lt;br /&gt;
&lt;br /&gt;
As far as I can tell, it has the same function as the &amp;quot;Get New Item to Add&amp;quot; button, i.e. it generates a new set of values and displays them in the &amp;quot;Item to Add&amp;quot; section. However, it is less conveniently placed that that button, so it is probably best ignored.&lt;br /&gt;
&lt;br /&gt;
==Correct answer formula syntax==&lt;br /&gt;
 &lt;br /&gt;
=== DO NOT PUT THE = sign in the formula. ===&lt;br /&gt;
 &lt;br /&gt;
* In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.&lt;br /&gt;
 If more than one correct answer formula input field are displayed when editing, &lt;br /&gt;
 your site has the multiple answer feature. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As a general rule, write these formulas like you would in a calculator e.g. &amp;lt;code&amp;gt;3 + 5 * sin(3/{x})&amp;lt;/code&amp;gt; A notable exception is exponentiation, where x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; cannot be entered as &amp;lt;code&amp;gt;{x}^3&amp;lt;/code&amp;gt;, but instead should be entered as &amp;lt;code&amp;gt;pow({x}, 3)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Each function&#039;s placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter &amp;lt;code&amp;gt;sin({a}) + cos({b}*2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* It&#039;s usually better to have too many parentheses (brackets) than too few.  The server won&#039;t care, and the more specific you are about what you mean, the more likely it will like your complex formulas.&lt;br /&gt;
* There is no implicit multiplication.  To you, the human editor, &amp;quot;5(23)&amp;quot; or &amp;quot;5x&amp;quot; may seem perfectly obvious.  To the server doing the math, it&#039;s crazy talk and won&#039;t be understood.  Always use the &amp;quot;*&amp;quot; for multiplication.&lt;br /&gt;
* Any special mathematical function must have parentheses around its values.  Take the sine function in the first bullet point for instance.  Notice that the &#039;&#039;3 / x&#039;&#039; is wrapped in parentheses (brackets)--this is so the server can understand it properly.  Without those parentheses, the server won&#039;t know if you mean &amp;quot;(sin 3) / x&amp;quot; or &amp;quot;sin (3 / x)&amp;quot; and will reject the entire formula accordingly.&lt;br /&gt;
&lt;br /&gt;
==Available functions==&lt;br /&gt;
&lt;br /&gt;
Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;97%&amp;quot; border=&amp;quot;1px&amp;quot;&lt;br /&gt;
!Function&lt;br /&gt;
!Explanation&lt;br /&gt;
|-&lt;br /&gt;
|abs&lt;br /&gt;
|Absolute value&lt;br /&gt;
|-&lt;br /&gt;
|acos&lt;br /&gt;
|Arc cosine -- in radians!!!  Convert your degree measurement to radians before you take the acos of it.&lt;br /&gt;
|-&lt;br /&gt;
|acosh&lt;br /&gt;
|Inverse hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the acosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|asin&lt;br /&gt;
|Arc sine -- in radians!!!  Convert your degree measurement to radians before you take the asin of it.&lt;br /&gt;
|-&lt;br /&gt;
|asinh&lt;br /&gt;
|Inverse hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the asing of it.&lt;br /&gt;
|-&lt;br /&gt;
|atan2&lt;br /&gt;
|Arc tangent of two variables -- pass in two values like (x, y), and you&#039;ll get the atah(y/x), adjusted to the proper quadrant.&lt;br /&gt;
|-&lt;br /&gt;
|atan&lt;br /&gt;
|Arc tangent -- in radians!!!  Convert your degree measurement to radians before you take the atan of it.&lt;br /&gt;
|-&lt;br /&gt;
|atanh&lt;br /&gt;
|Inverse hyperbolic tangent&lt;br /&gt;
|-&lt;br /&gt;
|bindec&lt;br /&gt;
|Binary to decimal&lt;br /&gt;
|-&lt;br /&gt;
|ceil&lt;br /&gt;
|Round fractions up&lt;br /&gt;
|-&lt;br /&gt;
|cos&lt;br /&gt;
|Cosine -- in radians!!!  Convert your degree measurement to radians before you take the cos of it.&lt;br /&gt;
|-&lt;br /&gt;
|cosh&lt;br /&gt;
|Hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the cosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|decbin&lt;br /&gt;
|Decimal to binary&lt;br /&gt;
|-&lt;br /&gt;
|decoct&lt;br /&gt;
|Decimal to octal&lt;br /&gt;
|-&lt;br /&gt;
|deg2rad&lt;br /&gt;
|Converts the number in degrees to the radian equivalent&lt;br /&gt;
|-&lt;br /&gt;
|exp&lt;br /&gt;
|Calculates the exponent of e&lt;br /&gt;
|-&lt;br /&gt;
|expm1&lt;br /&gt;
|Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|floor&lt;br /&gt;
|Round fractions down&lt;br /&gt;
|-&lt;br /&gt;
|fmod&lt;br /&gt;
|Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.&lt;br /&gt;
|-&lt;br /&gt;
|is_finite&lt;br /&gt;
|Finds whether a value is a legal finite number&lt;br /&gt;
|-&lt;br /&gt;
|is_infinite&lt;br /&gt;
|Finds whether a value is infinite&lt;br /&gt;
|-&lt;br /&gt;
|is_nan&lt;br /&gt;
|Finds whether a value is not a number&lt;br /&gt;
|-&lt;br /&gt;
|log10&lt;br /&gt;
|Base-10 logarithm&lt;br /&gt;
|-&lt;br /&gt;
|log1p&lt;br /&gt;
|Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|log&lt;br /&gt;
|Natural logarithm (&#039;&#039;ln&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|Find highest value&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|Find lowest value&lt;br /&gt;
|-&lt;br /&gt;
|octdec&lt;br /&gt;
|Octal to decimal&lt;br /&gt;
|-&lt;br /&gt;
|pi()&lt;br /&gt;
|Get value of pi - the function does not take an argument, like in Excel.&lt;br /&gt;
|-&lt;br /&gt;
|pow (numberToRaise, NumberRaisedTo)&lt;br /&gt;
|Exponential expression&lt;br /&gt;
|-&lt;br /&gt;
|rad2deg&lt;br /&gt;
|Converts the radian number to the equivalent number in degrees&lt;br /&gt;
|-&lt;br /&gt;
|rand&lt;br /&gt;
|Generate a random integer&lt;br /&gt;
|-&lt;br /&gt;
|round&lt;br /&gt;
|Rounds a float&lt;br /&gt;
|-&lt;br /&gt;
|sin&lt;br /&gt;
|Sine -- in radians!!!  Convert your degree measurement to radians before you take the sin of it.&lt;br /&gt;
|-&lt;br /&gt;
|sinh&lt;br /&gt;
|Hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the sinh of it.&lt;br /&gt;
|-&lt;br /&gt;
|sqrt&lt;br /&gt;
|Square root&lt;br /&gt;
|-&lt;br /&gt;
|tan&lt;br /&gt;
|Tangent -- in radians!!!  Convert your degree measurement to radians before you take the tan of it.&lt;br /&gt;
|-&lt;br /&gt;
|tanh&lt;br /&gt;
|Hyperbolic tangent -- in radians!!!  Convert your degree measurement to radians before you take the tanh of it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Predefined constants==&lt;br /&gt;
Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.&lt;br /&gt;
&lt;br /&gt;
==Synchronization==&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
You could use shared wild cards to get the same values across questions in a quiz.&lt;br /&gt;
&lt;br /&gt;
A simple example will be to use the same radius in a first question asking for the perimiter of a circle of {radius}cm and a second question asking for the surface of a circle of {radius}cm.&lt;br /&gt;
&lt;br /&gt;
When the quiz will be shown to the student the two questions will shown the same {radius} value.&lt;br /&gt;
&lt;br /&gt;
However the synchronization will work &#039;&#039;&#039;ONLY&#039;&#039;&#039; if the questions are kept in the &#039;&#039;&#039;SAME&#039;&#039;&#039; category and have the &#039;&#039;&#039;SAME NUMBER OF DATASETS&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
If you need to move the synchronized questions to another category, you need to do it by editing the questions.&lt;br /&gt;
&lt;br /&gt;
(This restriction should be released by sept. 2010).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=150923 couple questions about &amp;quot;edit datasets page&amp;quot; in calculated questions] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
&lt;br /&gt;
[[de:Berechnungsfragen]]&lt;br /&gt;
[[fr:Question calculée]]&lt;br /&gt;
[[zh:計算題]]&lt;br /&gt;
[[ja:計算問題タイプ]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=73184</id>
		<title>Calculated question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=73184"/>
		<updated>2010-06-18T08:42:17Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Synchronization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
Calculated questions offer a way to create individual numerical questions by the use of wildcards  (i.e &#039;&#039;&#039;{x}&#039;&#039;&#039; , &#039;&#039;&#039;{y}&#039;&#039;&#039;) that are substituted with random values when the quiz is taken.&lt;br /&gt;
 &lt;br /&gt;
For example, if you want to create a large number of &#039;&#039;&#039;&amp;quot;Calculate the area of a rectangle&amp;quot;&#039;&#039;&#039; problems to drill your students, you could create a question with two wildcards (i.e. &#039;&#039;&#039;{base}&#039;&#039;&#039;, &#039;&#039;&#039;{height}&#039;&#039;&#039;) and put in the &amp;quot;&#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039;&amp;quot; input field  &#039;&#039;&#039;{base}&#039;&#039;&#039; * &#039;&#039;&#039;{height}&#039;&#039;&#039; ( * being the multiplication sign ).&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039; {base}*{height}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
When a student takes the test, Moodle will randomly select values for &#039;&#039;&#039;{base}&#039;&#039;&#039; and &#039;&#039;&#039;{height}&#039;&#039;&#039; and grade the response using the result of the &#039;&#039;&#039;Correct Answer Formula&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
The test will very rarely appear the same way twice.&lt;br /&gt;
&lt;br /&gt;
== Is this really the question type for you? ==&lt;br /&gt;
The main purpose of the calculated question is to create multiple versions of a question with different numerical values. This means you must have &#039;&#039;&#039;at least one&#039;&#039;&#039; wildcard in one of the answers.&lt;br /&gt;
 &lt;br /&gt;
If you don&#039;t need a random element, use the [[Numerical question type]] instead.&lt;br /&gt;
&lt;br /&gt;
==Wildcards and datasets==&lt;br /&gt;
&lt;br /&gt;
When Moodle delivers a Calculated question to the student, the wildcards are replaced with randomly-selected values. However, these values are not completely random - rather, they are randomly selected from a pre-defined &#039;&#039;dataset&#039;&#039; of possible values. This allows you some control over the possible values chosen - for example, in order to make sure the numbers are realistic.&lt;br /&gt;
&lt;br /&gt;
These datasets can be &#039;&#039;private&#039;&#039; or &#039;&#039;shared&#039;&#039; - private datasets are used by one wildcard within one calculated question; shared datasets are used by one wildcard within all calculated questions that use it.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
To create (or modify) a calculated question there are three pages to work through. The instructions below take you through the pages, step by step:&lt;br /&gt;
&lt;br /&gt;
===Page 1. Editing a Calculated question ===&lt;br /&gt;
&lt;br /&gt;
#Select the question &#039;&#039;&#039;category&#039;&#039;&#039;&lt;br /&gt;
#Any shared wildcards for this category are listed beneath. If you change category, you&#039;ll need to click the &amp;quot;Update the category&amp;quot; button to refresh this list. There may not be any shared wildcards yet - if not, you can create them later if you wish.&lt;br /&gt;
#Give the question a descriptive &#039;&#039;&#039;name&#039;&#039;&#039; - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the &#039;&#039;&#039;question text&#039;&#039;&#039;. This should be the question you want the student to answer, and it must include all the information they need to calculate an answer. Therefore it must contain at least one wildcard, inside curly braces. For example, if you wanted the student to sum numbers A and B, the question text might read: &amp;quot;What is {A} + {B}?&amp;quot;&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices. If you want more control over how the image appears, include it in the question text above, using the HTML editor.&lt;br /&gt;
#Set the &#039;&#039;&#039;default question grade&#039;&#039;&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;&#039;&#039;Penalty factor&#039;&#039;&#039; (see [[Calculated_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#&#039;&#039;Moodle 1.7+:&#039;&#039; If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Next add the &#039;&#039;&#039;formula for the answer&#039;&#039;&#039;. This formula must contain at least the wildcards that appear in the question text. See [[Calculated_question_type#Correct_answer_formula_syntax|Correct answer formula syntax]] for further details.&lt;br /&gt;
# Choose the &#039;&#039;&#039;grade&#039;&#039;&#039; that the student will get for this question if they give this answer. This should be a percentage of the total marks available. For example, you could give 100% for a correct answer, and 50% for an answer that is nearly right. &#039;&#039;&#039;One of the answers must have a 100% grade&#039;&#039;&#039;.&lt;br /&gt;
#Determine the &#039;&#039;&#039;tolerance&#039;&#039;&#039; for error that you will accept in the answer. The tolerance and tolerance type settings combine to give a range of acceptable scores. So, if tolerance = t, correct answer = x and the difference between the user&#039;s answer and the correct answer is dx, then the tolerance types are as follows:&lt;br /&gt;
##Nominal - mark correct if dx &amp;lt;= t&lt;br /&gt;
##Relative - mark correct if dx / x &amp;lt;= t&lt;br /&gt;
##Geometric - mark correct if dx² / x² &amp;lt;= t²&lt;br /&gt;
# The next 2 settings, &amp;quot;Correct answer shows&amp;quot; and &amp;quot;Format&amp;quot; determine the &#039;&#039;&#039;precision&#039;&#039;&#039; of the answer. Use these to select the number of decimal places or significant figures you want to use.&lt;br /&gt;
# Add some &#039;&#039;&#039;feedback&#039;&#039;&#039; which the student will see if they enter this answer.&lt;br /&gt;
# You can specify as many answer formulae as you like - click &amp;quot;Add another answer blank&amp;quot; to add more.&lt;br /&gt;
# You can also specify units for the answers. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. If you add more than one unit, you can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
# Finally (!) you can click &amp;quot;Next page&amp;quot; to save what you&#039;ve done and move on. If you are editing an existing question, you can click &amp;quot;Next page (new question)&amp;quot; to create a completely new question based on an existing one.&lt;br /&gt;
&lt;br /&gt;
==== Penalty factor ====&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
===Tolerance===&lt;br /&gt;
&lt;br /&gt;
As for numerical questions it is possible to allow a margin within which all responses are accepted as correct. The &amp;quot;Tolerance&amp;quot; field is used for this. However, there are three different types of tolerances. These are Relative, Nominal and Geometric. If we say that the correct answer at quiz time is calculated to 200 and the tolerance is set to 0.5 then the different tolerance types work like this:&lt;br /&gt;
&lt;br /&gt;
Relative: A tolerance interval is calculated by multiplying the correct answer with 0.5, ie in this case we get 100 so for this tolerance the correct response must be between 100 and 300. (200 ± 100)&lt;br /&gt;
This is useful if the magnitude of the correct answer can differ greatly between different wildcard values.&lt;br /&gt;
&lt;br /&gt;
Nominal: This is the simplest tolerance type but not very powerful. The correct response must be between 199.5 and 200.5 (200 ± 0.5)&lt;br /&gt;
This tolerance type can be useful if the differences between different correct answers are small.&lt;br /&gt;
&lt;br /&gt;
Geometric: The upper limit of the tolerance interval is calculated as 200 + 0.5*200 and is the same as for the relative case. The lower limit is calculated as 200/(1 + 0.5). The correct response must then be between 133.33 and 300.&lt;br /&gt;
This is useful for complex calculation that must have great tolerances where relative tolerances of 1 or more would be used for the upper limit but clearly not acceptable for the lower limit as it would make zero a correct answer for all cases.&lt;br /&gt;
&lt;br /&gt;
The field Significant Figures does only relate to how the correct answer should be presented in the review or the reports. Examples: If it is set to 3 then the correct answer 13.333 would be presented as 13.3; 1236 would be presented as 1240; 23 would be presented as 23.0 etc. &lt;br /&gt;
&lt;br /&gt;
===Page 2. Choose dataset properties ===&lt;br /&gt;
&lt;br /&gt;
Each wildcard that you specify in the answer formula must have an associated set of possible values - this is its &#039;&#039;dataset&#039;&#039;. Each of the wildcards is listed on this page along with a choice of dataset:&lt;br /&gt;
*&#039;&#039;&#039;private&#039;&#039;&#039; i.e. only used by this question&lt;br /&gt;
*&#039;&#039;&#039;shared&#039;&#039;&#039; i.e shared with other calculated questions in the same category&lt;br /&gt;
&lt;br /&gt;
Using a shared dataset can save time when you are creating a lot of similar calculated questions.&lt;br /&gt;
&lt;br /&gt;
If there is anything in the question text that looks like a wildcard, but does not appear in any of the answer formulae, you can specify whether or not this is meant to be a wildcard. If it is, you can choose whether it should use a private or shared dataset.&lt;br /&gt;
&lt;br /&gt;
To continue, simply choose your preferred dataset for each wildcard, then click &amp;quot;Next Page&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Page 3. Edit the datasets ===&lt;br /&gt;
&lt;br /&gt;
Now we need to create the set of possible values that each wildcard can take. &#039;&#039;Warning&#039;&#039; - this page is a bit confusing!&lt;br /&gt;
&lt;br /&gt;
There are two ways of creating values - you can type them in yourself and add them to the list, or you can have Moodle generate them for you.&lt;br /&gt;
&lt;br /&gt;
==== Adding/deleting your own values ====&lt;br /&gt;
&lt;br /&gt;
Adding individual values to the list is easy:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Param&#039; field for each wildcard, enter the value you want&lt;br /&gt;
# Scroll down to the &#039;Add&#039; section and click the Add button (leaving the number of items set to 1)&lt;br /&gt;
# Repeat the above steps as many times as necessary (the maximum number of items is 100)&lt;br /&gt;
&lt;br /&gt;
To delete values from the list:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Delete&#039; section, select the number of items to delete&lt;br /&gt;
# Click the Delete button&lt;br /&gt;
&lt;br /&gt;
==== Letting Moodle create values ====&lt;br /&gt;
&lt;br /&gt;
# Start with the &amp;quot;Range of Values&amp;quot; fields, and enter the lower and upper limits for the values you would accept&lt;br /&gt;
# Choose a number of decimal places for the value&lt;br /&gt;
# Choose the distribution of values between the limits - &#039;uniform&#039; means any value between the limits is equally likely to be generated; &#039;loguniform&#039; means that values towards the lower limit are more likely.&lt;br /&gt;
# Now move down to the &#039;Add&#039; section and click on &amp;quot;force regeneration&amp;quot;&lt;br /&gt;
# In the menu next to the Add button, choose the number of sets of random values (items) you wish to add to the list. (Note that the maximum total number of items in your list is 100.)&lt;br /&gt;
# Finally, click Add to append the new values to the list&lt;br /&gt;
# &#039;&#039;&#039;Note:&#039;&#039;&#039; If you want more control over the items that Moodle adds, you can do them one at a time and preview the values before you add them. Click the &amp;quot;Get New Item to Add&amp;quot; button to make Moodle generate new values in the &amp;quot;Item to Add&amp;quot; section at the top. If you like them, click &amp;quot;Add&amp;quot; for 1 item; if not, click &amp;quot;Get New Item to Add&amp;quot; again to get new values.&lt;br /&gt;
&lt;br /&gt;
==== Finishing off ====&lt;br /&gt;
&lt;br /&gt;
Once your list of items (values) is complete, you are finished. It&#039;s up to you how many values you add - the more values you add, the more a question can be used by the students without them seeing the same values repeatedly.&lt;br /&gt;
&lt;br /&gt;
Note that if you delete values from the list, you can put them back again. Change the &amp;quot;Next Item to Add&amp;quot; option to &amp;quot;reuse previous value if available&amp;quot;, then the next time you add items, Moodle will restore your previously-deleted items from the dataset. &lt;br /&gt;
&lt;br /&gt;
Once your list of values is complete, you can click &#039;Save changes&#039; to finish.&lt;br /&gt;
&lt;br /&gt;
==== What does the &#039;Update the datasets parameters&#039; button do? ====&lt;br /&gt;
&lt;br /&gt;
As far as I can tell, it has the same function as the &amp;quot;Get New Item to Add&amp;quot; button, i.e. it generates a new set of values and displays them in the &amp;quot;Item to Add&amp;quot; section. However, it is less conveniently placed that that button, so it is probably best ignored.&lt;br /&gt;
&lt;br /&gt;
==Correct answer formula syntax==&lt;br /&gt;
 &lt;br /&gt;
=== DO NOT PUT THE = sign in the formula. ===&lt;br /&gt;
 &lt;br /&gt;
* In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.&lt;br /&gt;
 If more than one correct answer formula input field are displayed when editing, &lt;br /&gt;
 your site has the multiple answer feature. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As a general rule, write these formulas like you would in a calculator e.g. &amp;lt;code&amp;gt;3 + 5 * sin(3/{x})&amp;lt;/code&amp;gt; A notable exception is exponentiation, where x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; cannot be entered as &amp;lt;code&amp;gt;{x}^3&amp;lt;/code&amp;gt;, but instead should be entered as &amp;lt;code&amp;gt;pow({x}, 3)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Each function&#039;s placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter &amp;lt;code&amp;gt;sin({a}) + cos({b}*2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* It&#039;s usually better to have too many parentheses (brackets) than too few.  The server won&#039;t care, and the more specific you are about what you mean, the more likely it will like your complex formulas.&lt;br /&gt;
* There is no implicit multiplication.  To you, the human editor, &amp;quot;5(23)&amp;quot; or &amp;quot;5x&amp;quot; may seem perfectly obvious.  To the server doing the math, it&#039;s crazy talk and won&#039;t be understood.  Always use the &amp;quot;*&amp;quot; for multiplication.&lt;br /&gt;
* Any special mathematical function must have parentheses around its values.  Take the sine function in the first bullet point for instance.  Notice that the &#039;&#039;3 / x&#039;&#039; is wrapped in parentheses (brackets)--this is so the server can understand it properly.  Without those parentheses, the server won&#039;t know if you mean &amp;quot;(sin 3) / x&amp;quot; or &amp;quot;sin (3 / x)&amp;quot; and will reject the entire formula accordingly.&lt;br /&gt;
&lt;br /&gt;
==Available functions==&lt;br /&gt;
&lt;br /&gt;
Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;97%&amp;quot; border=&amp;quot;1px&amp;quot;&lt;br /&gt;
!Function&lt;br /&gt;
!Explanation&lt;br /&gt;
|-&lt;br /&gt;
|abs&lt;br /&gt;
|Absolute value&lt;br /&gt;
|-&lt;br /&gt;
|acos&lt;br /&gt;
|Arc cosine -- in radians!!!  Convert your degree measurement to radians before you take the acos of it.&lt;br /&gt;
|-&lt;br /&gt;
|acosh&lt;br /&gt;
|Inverse hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the acosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|asin&lt;br /&gt;
|Arc sine -- in radians!!!  Convert your degree measurement to radians before you take the asin of it.&lt;br /&gt;
|-&lt;br /&gt;
|asinh&lt;br /&gt;
|Inverse hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the asing of it.&lt;br /&gt;
|-&lt;br /&gt;
|atan2&lt;br /&gt;
|Arc tangent of two variables -- pass in two values like (x, y), and you&#039;ll get the atah(y/x), adjusted to the proper quadrant.&lt;br /&gt;
|-&lt;br /&gt;
|atan&lt;br /&gt;
|Arc tangent -- in radians!!!  Convert your degree measurement to radians before you take the atan of it.&lt;br /&gt;
|-&lt;br /&gt;
|atanh&lt;br /&gt;
|Inverse hyperbolic tangent&lt;br /&gt;
|-&lt;br /&gt;
|bindec&lt;br /&gt;
|Binary to decimal&lt;br /&gt;
|-&lt;br /&gt;
|ceil&lt;br /&gt;
|Round fractions up&lt;br /&gt;
|-&lt;br /&gt;
|cos&lt;br /&gt;
|Cosine -- in radians!!!  Convert your degree measurement to radians before you take the cos of it.&lt;br /&gt;
|-&lt;br /&gt;
|cosh&lt;br /&gt;
|Hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the cosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|decbin&lt;br /&gt;
|Decimal to binary&lt;br /&gt;
|-&lt;br /&gt;
|decoct&lt;br /&gt;
|Decimal to octal&lt;br /&gt;
|-&lt;br /&gt;
|deg2rad&lt;br /&gt;
|Converts the number in degrees to the radian equivalent&lt;br /&gt;
|-&lt;br /&gt;
|exp&lt;br /&gt;
|Calculates the exponent of e&lt;br /&gt;
|-&lt;br /&gt;
|expm1&lt;br /&gt;
|Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|floor&lt;br /&gt;
|Round fractions down&lt;br /&gt;
|-&lt;br /&gt;
|fmod&lt;br /&gt;
|Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.&lt;br /&gt;
|-&lt;br /&gt;
|is_finite&lt;br /&gt;
|Finds whether a value is a legal finite number&lt;br /&gt;
|-&lt;br /&gt;
|is_infinite&lt;br /&gt;
|Finds whether a value is infinite&lt;br /&gt;
|-&lt;br /&gt;
|is_nan&lt;br /&gt;
|Finds whether a value is not a number&lt;br /&gt;
|-&lt;br /&gt;
|log10&lt;br /&gt;
|Base-10 logarithm&lt;br /&gt;
|-&lt;br /&gt;
|log1p&lt;br /&gt;
|Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|log&lt;br /&gt;
|Natural logarithm (&#039;&#039;ln&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|Find highest value&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|Find lowest value&lt;br /&gt;
|-&lt;br /&gt;
|octdec&lt;br /&gt;
|Octal to decimal&lt;br /&gt;
|-&lt;br /&gt;
|pi()&lt;br /&gt;
|Get value of pi - the function does not take an argument, like in Excel.&lt;br /&gt;
|-&lt;br /&gt;
|pow (numberToRaise, NumberRaisedTo)&lt;br /&gt;
|Exponential expression&lt;br /&gt;
|-&lt;br /&gt;
|rad2deg&lt;br /&gt;
|Converts the radian number to the equivalent number in degrees&lt;br /&gt;
|-&lt;br /&gt;
|rand&lt;br /&gt;
|Generate a random integer&lt;br /&gt;
|-&lt;br /&gt;
|round&lt;br /&gt;
|Rounds a float&lt;br /&gt;
|-&lt;br /&gt;
|sin&lt;br /&gt;
|Sine -- in radians!!!  Convert your degree measurement to radians before you take the sin of it.&lt;br /&gt;
|-&lt;br /&gt;
|sinh&lt;br /&gt;
|Hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the sinh of it.&lt;br /&gt;
|-&lt;br /&gt;
|sqrt&lt;br /&gt;
|Square root&lt;br /&gt;
|-&lt;br /&gt;
|tan&lt;br /&gt;
|Tangent -- in radians!!!  Convert your degree measurement to radians before you take the tan of it.&lt;br /&gt;
|-&lt;br /&gt;
|tanh&lt;br /&gt;
|Hyperbolic tangent -- in radians!!!  Convert your degree measurement to radians before you take the tanh of it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Predefined constants==&lt;br /&gt;
Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.&lt;br /&gt;
&lt;br /&gt;
==Synchronization==&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
You could use shared wild cards to get the same values across questions in a quiz.&lt;br /&gt;
&lt;br /&gt;
A simple example will be to use the same radius in a first question asking for the perimiter of a circle of {radius}cm and a second question asking for the surface of a circle of {radius}cm.&lt;br /&gt;
&lt;br /&gt;
When the quiz will be shown to the student the two questions will shown the same {radius} value.&lt;br /&gt;
&lt;br /&gt;
However the synchronization will work &#039;&#039;&#039;ONLY&#039;&#039;&#039; if the questions are kept in the &#039;&#039;&#039;SAME&#039;&#039;&#039; category and have the &#039;&#039;&#039;SAME NUMBER OF DATASETS&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
If you need to move the synchronized questions to another category, you need to do it by editing the questions.&lt;br /&gt;
&lt;br /&gt;
(This restriction should be released by sept. 2010).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=150923 couple questions about &amp;quot;edit datasets page&amp;quot; in calculated questions] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
&lt;br /&gt;
[[de:Berechnungsfragen]]&lt;br /&gt;
[[fr:Question calculée]]&lt;br /&gt;
[[zh:計算題]]&lt;br /&gt;
[[ja:計算問題タイプ]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=73182</id>
		<title>Calculated question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=73182"/>
		<updated>2010-06-18T08:39:57Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Synchronization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
Calculated questions offer a way to create individual numerical questions by the use of wildcards  (i.e &#039;&#039;&#039;{x}&#039;&#039;&#039; , &#039;&#039;&#039;{y}&#039;&#039;&#039;) that are substituted with random values when the quiz is taken.&lt;br /&gt;
 &lt;br /&gt;
For example, if you want to create a large number of &#039;&#039;&#039;&amp;quot;Calculate the area of a rectangle&amp;quot;&#039;&#039;&#039; problems to drill your students, you could create a question with two wildcards (i.e. &#039;&#039;&#039;{base}&#039;&#039;&#039;, &#039;&#039;&#039;{height}&#039;&#039;&#039;) and put in the &amp;quot;&#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039;&amp;quot; input field  &#039;&#039;&#039;{base}&#039;&#039;&#039; * &#039;&#039;&#039;{height}&#039;&#039;&#039; ( * being the multiplication sign ).&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039; {base}*{height}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
When a student takes the test, Moodle will randomly select values for &#039;&#039;&#039;{base}&#039;&#039;&#039; and &#039;&#039;&#039;{height}&#039;&#039;&#039; and grade the response using the result of the &#039;&#039;&#039;Correct Answer Formula&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
The test will very rarely appear the same way twice.&lt;br /&gt;
&lt;br /&gt;
== Is this really the question type for you? ==&lt;br /&gt;
The main purpose of the calculated question is to create multiple versions of a question with different numerical values. This means you must have &#039;&#039;&#039;at least one&#039;&#039;&#039; wildcard in one of the answers.&lt;br /&gt;
 &lt;br /&gt;
If you don&#039;t need a random element, use the [[Numerical question type]] instead.&lt;br /&gt;
&lt;br /&gt;
==Wildcards and datasets==&lt;br /&gt;
&lt;br /&gt;
When Moodle delivers a Calculated question to the student, the wildcards are replaced with randomly-selected values. However, these values are not completely random - rather, they are randomly selected from a pre-defined &#039;&#039;dataset&#039;&#039; of possible values. This allows you some control over the possible values chosen - for example, in order to make sure the numbers are realistic.&lt;br /&gt;
&lt;br /&gt;
These datasets can be &#039;&#039;private&#039;&#039; or &#039;&#039;shared&#039;&#039; - private datasets are used by one wildcard within one calculated question; shared datasets are used by one wildcard within all calculated questions that use it.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
To create (or modify) a calculated question there are three pages to work through. The instructions below take you through the pages, step by step:&lt;br /&gt;
&lt;br /&gt;
===Page 1. Editing a Calculated question ===&lt;br /&gt;
&lt;br /&gt;
#Select the question &#039;&#039;&#039;category&#039;&#039;&#039;&lt;br /&gt;
#Any shared wildcards for this category are listed beneath. If you change category, you&#039;ll need to click the &amp;quot;Update the category&amp;quot; button to refresh this list. There may not be any shared wildcards yet - if not, you can create them later if you wish.&lt;br /&gt;
#Give the question a descriptive &#039;&#039;&#039;name&#039;&#039;&#039; - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the &#039;&#039;&#039;question text&#039;&#039;&#039;. This should be the question you want the student to answer, and it must include all the information they need to calculate an answer. Therefore it must contain at least one wildcard, inside curly braces. For example, if you wanted the student to sum numbers A and B, the question text might read: &amp;quot;What is {A} + {B}?&amp;quot;&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices. If you want more control over how the image appears, include it in the question text above, using the HTML editor.&lt;br /&gt;
#Set the &#039;&#039;&#039;default question grade&#039;&#039;&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;&#039;&#039;Penalty factor&#039;&#039;&#039; (see [[Calculated_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#&#039;&#039;Moodle 1.7+:&#039;&#039; If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Next add the &#039;&#039;&#039;formula for the answer&#039;&#039;&#039;. This formula must contain at least the wildcards that appear in the question text. See [[Calculated_question_type#Correct_answer_formula_syntax|Correct answer formula syntax]] for further details.&lt;br /&gt;
# Choose the &#039;&#039;&#039;grade&#039;&#039;&#039; that the student will get for this question if they give this answer. This should be a percentage of the total marks available. For example, you could give 100% for a correct answer, and 50% for an answer that is nearly right. &#039;&#039;&#039;One of the answers must have a 100% grade&#039;&#039;&#039;.&lt;br /&gt;
#Determine the &#039;&#039;&#039;tolerance&#039;&#039;&#039; for error that you will accept in the answer. The tolerance and tolerance type settings combine to give a range of acceptable scores. So, if tolerance = t, correct answer = x and the difference between the user&#039;s answer and the correct answer is dx, then the tolerance types are as follows:&lt;br /&gt;
##Nominal - mark correct if dx &amp;lt;= t&lt;br /&gt;
##Relative - mark correct if dx / x &amp;lt;= t&lt;br /&gt;
##Geometric - mark correct if dx² / x² &amp;lt;= t²&lt;br /&gt;
# The next 2 settings, &amp;quot;Correct answer shows&amp;quot; and &amp;quot;Format&amp;quot; determine the &#039;&#039;&#039;precision&#039;&#039;&#039; of the answer. Use these to select the number of decimal places or significant figures you want to use.&lt;br /&gt;
# Add some &#039;&#039;&#039;feedback&#039;&#039;&#039; which the student will see if they enter this answer.&lt;br /&gt;
# You can specify as many answer formulae as you like - click &amp;quot;Add another answer blank&amp;quot; to add more.&lt;br /&gt;
# You can also specify units for the answers. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. If you add more than one unit, you can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
# Finally (!) you can click &amp;quot;Next page&amp;quot; to save what you&#039;ve done and move on. If you are editing an existing question, you can click &amp;quot;Next page (new question)&amp;quot; to create a completely new question based on an existing one.&lt;br /&gt;
&lt;br /&gt;
==== Penalty factor ====&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
===Tolerance===&lt;br /&gt;
&lt;br /&gt;
As for numerical questions it is possible to allow a margin within which all responses are accepted as correct. The &amp;quot;Tolerance&amp;quot; field is used for this. However, there are three different types of tolerances. These are Relative, Nominal and Geometric. If we say that the correct answer at quiz time is calculated to 200 and the tolerance is set to 0.5 then the different tolerance types work like this:&lt;br /&gt;
&lt;br /&gt;
Relative: A tolerance interval is calculated by multiplying the correct answer with 0.5, ie in this case we get 100 so for this tolerance the correct response must be between 100 and 300. (200 ± 100)&lt;br /&gt;
This is useful if the magnitude of the correct answer can differ greatly between different wildcard values.&lt;br /&gt;
&lt;br /&gt;
Nominal: This is the simplest tolerance type but not very powerful. The correct response must be between 199.5 and 200.5 (200 ± 0.5)&lt;br /&gt;
This tolerance type can be useful if the differences between different correct answers are small.&lt;br /&gt;
&lt;br /&gt;
Geometric: The upper limit of the tolerance interval is calculated as 200 + 0.5*200 and is the same as for the relative case. The lower limit is calculated as 200/(1 + 0.5). The correct response must then be between 133.33 and 300.&lt;br /&gt;
This is useful for complex calculation that must have great tolerances where relative tolerances of 1 or more would be used for the upper limit but clearly not acceptable for the lower limit as it would make zero a correct answer for all cases.&lt;br /&gt;
&lt;br /&gt;
The field Significant Figures does only relate to how the correct answer should be presented in the review or the reports. Examples: If it is set to 3 then the correct answer 13.333 would be presented as 13.3; 1236 would be presented as 1240; 23 would be presented as 23.0 etc. &lt;br /&gt;
&lt;br /&gt;
===Page 2. Choose dataset properties ===&lt;br /&gt;
&lt;br /&gt;
Each wildcard that you specify in the answer formula must have an associated set of possible values - this is its &#039;&#039;dataset&#039;&#039;. Each of the wildcards is listed on this page along with a choice of dataset:&lt;br /&gt;
*&#039;&#039;&#039;private&#039;&#039;&#039; i.e. only used by this question&lt;br /&gt;
*&#039;&#039;&#039;shared&#039;&#039;&#039; i.e shared with other calculated questions in the same category&lt;br /&gt;
&lt;br /&gt;
Using a shared dataset can save time when you are creating a lot of similar calculated questions.&lt;br /&gt;
&lt;br /&gt;
If there is anything in the question text that looks like a wildcard, but does not appear in any of the answer formulae, you can specify whether or not this is meant to be a wildcard. If it is, you can choose whether it should use a private or shared dataset.&lt;br /&gt;
&lt;br /&gt;
To continue, simply choose your preferred dataset for each wildcard, then click &amp;quot;Next Page&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Page 3. Edit the datasets ===&lt;br /&gt;
&lt;br /&gt;
Now we need to create the set of possible values that each wildcard can take. &#039;&#039;Warning&#039;&#039; - this page is a bit confusing!&lt;br /&gt;
&lt;br /&gt;
There are two ways of creating values - you can type them in yourself and add them to the list, or you can have Moodle generate them for you.&lt;br /&gt;
&lt;br /&gt;
==== Adding/deleting your own values ====&lt;br /&gt;
&lt;br /&gt;
Adding individual values to the list is easy:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Param&#039; field for each wildcard, enter the value you want&lt;br /&gt;
# Scroll down to the &#039;Add&#039; section and click the Add button (leaving the number of items set to 1)&lt;br /&gt;
# Repeat the above steps as many times as necessary (the maximum number of items is 100)&lt;br /&gt;
&lt;br /&gt;
To delete values from the list:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Delete&#039; section, select the number of items to delete&lt;br /&gt;
# Click the Delete button&lt;br /&gt;
&lt;br /&gt;
==== Letting Moodle create values ====&lt;br /&gt;
&lt;br /&gt;
# Start with the &amp;quot;Range of Values&amp;quot; fields, and enter the lower and upper limits for the values you would accept&lt;br /&gt;
# Choose a number of decimal places for the value&lt;br /&gt;
# Choose the distribution of values between the limits - &#039;uniform&#039; means any value between the limits is equally likely to be generated; &#039;loguniform&#039; means that values towards the lower limit are more likely.&lt;br /&gt;
# Now move down to the &#039;Add&#039; section and click on &amp;quot;force regeneration&amp;quot;&lt;br /&gt;
# In the menu next to the Add button, choose the number of sets of random values (items) you wish to add to the list. (Note that the maximum total number of items in your list is 100.)&lt;br /&gt;
# Finally, click Add to append the new values to the list&lt;br /&gt;
# &#039;&#039;&#039;Note:&#039;&#039;&#039; If you want more control over the items that Moodle adds, you can do them one at a time and preview the values before you add them. Click the &amp;quot;Get New Item to Add&amp;quot; button to make Moodle generate new values in the &amp;quot;Item to Add&amp;quot; section at the top. If you like them, click &amp;quot;Add&amp;quot; for 1 item; if not, click &amp;quot;Get New Item to Add&amp;quot; again to get new values.&lt;br /&gt;
&lt;br /&gt;
==== Finishing off ====&lt;br /&gt;
&lt;br /&gt;
Once your list of items (values) is complete, you are finished. It&#039;s up to you how many values you add - the more values you add, the more a question can be used by the students without them seeing the same values repeatedly.&lt;br /&gt;
&lt;br /&gt;
Note that if you delete values from the list, you can put them back again. Change the &amp;quot;Next Item to Add&amp;quot; option to &amp;quot;reuse previous value if available&amp;quot;, then the next time you add items, Moodle will restore your previously-deleted items from the dataset. &lt;br /&gt;
&lt;br /&gt;
Once your list of values is complete, you can click &#039;Save changes&#039; to finish.&lt;br /&gt;
&lt;br /&gt;
==== What does the &#039;Update the datasets parameters&#039; button do? ====&lt;br /&gt;
&lt;br /&gt;
As far as I can tell, it has the same function as the &amp;quot;Get New Item to Add&amp;quot; button, i.e. it generates a new set of values and displays them in the &amp;quot;Item to Add&amp;quot; section. However, it is less conveniently placed that that button, so it is probably best ignored.&lt;br /&gt;
&lt;br /&gt;
==Correct answer formula syntax==&lt;br /&gt;
 &lt;br /&gt;
=== DO NOT PUT THE = sign in the formula. ===&lt;br /&gt;
 &lt;br /&gt;
* In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.&lt;br /&gt;
 If more than one correct answer formula input field are displayed when editing, &lt;br /&gt;
 your site has the multiple answer feature. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As a general rule, write these formulas like you would in a calculator e.g. &amp;lt;code&amp;gt;3 + 5 * sin(3/{x})&amp;lt;/code&amp;gt; A notable exception is exponentiation, where x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; cannot be entered as &amp;lt;code&amp;gt;{x}^3&amp;lt;/code&amp;gt;, but instead should be entered as &amp;lt;code&amp;gt;pow({x}, 3)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Each function&#039;s placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter &amp;lt;code&amp;gt;sin({a}) + cos({b}*2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* It&#039;s usually better to have too many parentheses (brackets) than too few.  The server won&#039;t care, and the more specific you are about what you mean, the more likely it will like your complex formulas.&lt;br /&gt;
* There is no implicit multiplication.  To you, the human editor, &amp;quot;5(23)&amp;quot; or &amp;quot;5x&amp;quot; may seem perfectly obvious.  To the server doing the math, it&#039;s crazy talk and won&#039;t be understood.  Always use the &amp;quot;*&amp;quot; for multiplication.&lt;br /&gt;
* Any special mathematical function must have parentheses around its values.  Take the sine function in the first bullet point for instance.  Notice that the &#039;&#039;3 / x&#039;&#039; is wrapped in parentheses (brackets)--this is so the server can understand it properly.  Without those parentheses, the server won&#039;t know if you mean &amp;quot;(sin 3) / x&amp;quot; or &amp;quot;sin (3 / x)&amp;quot; and will reject the entire formula accordingly.&lt;br /&gt;
&lt;br /&gt;
==Available functions==&lt;br /&gt;
&lt;br /&gt;
Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;97%&amp;quot; border=&amp;quot;1px&amp;quot;&lt;br /&gt;
!Function&lt;br /&gt;
!Explanation&lt;br /&gt;
|-&lt;br /&gt;
|abs&lt;br /&gt;
|Absolute value&lt;br /&gt;
|-&lt;br /&gt;
|acos&lt;br /&gt;
|Arc cosine -- in radians!!!  Convert your degree measurement to radians before you take the acos of it.&lt;br /&gt;
|-&lt;br /&gt;
|acosh&lt;br /&gt;
|Inverse hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the acosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|asin&lt;br /&gt;
|Arc sine -- in radians!!!  Convert your degree measurement to radians before you take the asin of it.&lt;br /&gt;
|-&lt;br /&gt;
|asinh&lt;br /&gt;
|Inverse hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the asing of it.&lt;br /&gt;
|-&lt;br /&gt;
|atan2&lt;br /&gt;
|Arc tangent of two variables -- pass in two values like (x, y), and you&#039;ll get the atah(y/x), adjusted to the proper quadrant.&lt;br /&gt;
|-&lt;br /&gt;
|atan&lt;br /&gt;
|Arc tangent -- in radians!!!  Convert your degree measurement to radians before you take the atan of it.&lt;br /&gt;
|-&lt;br /&gt;
|atanh&lt;br /&gt;
|Inverse hyperbolic tangent&lt;br /&gt;
|-&lt;br /&gt;
|bindec&lt;br /&gt;
|Binary to decimal&lt;br /&gt;
|-&lt;br /&gt;
|ceil&lt;br /&gt;
|Round fractions up&lt;br /&gt;
|-&lt;br /&gt;
|cos&lt;br /&gt;
|Cosine -- in radians!!!  Convert your degree measurement to radians before you take the cos of it.&lt;br /&gt;
|-&lt;br /&gt;
|cosh&lt;br /&gt;
|Hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the cosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|decbin&lt;br /&gt;
|Decimal to binary&lt;br /&gt;
|-&lt;br /&gt;
|decoct&lt;br /&gt;
|Decimal to octal&lt;br /&gt;
|-&lt;br /&gt;
|deg2rad&lt;br /&gt;
|Converts the number in degrees to the radian equivalent&lt;br /&gt;
|-&lt;br /&gt;
|exp&lt;br /&gt;
|Calculates the exponent of e&lt;br /&gt;
|-&lt;br /&gt;
|expm1&lt;br /&gt;
|Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|floor&lt;br /&gt;
|Round fractions down&lt;br /&gt;
|-&lt;br /&gt;
|fmod&lt;br /&gt;
|Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.&lt;br /&gt;
|-&lt;br /&gt;
|is_finite&lt;br /&gt;
|Finds whether a value is a legal finite number&lt;br /&gt;
|-&lt;br /&gt;
|is_infinite&lt;br /&gt;
|Finds whether a value is infinite&lt;br /&gt;
|-&lt;br /&gt;
|is_nan&lt;br /&gt;
|Finds whether a value is not a number&lt;br /&gt;
|-&lt;br /&gt;
|log10&lt;br /&gt;
|Base-10 logarithm&lt;br /&gt;
|-&lt;br /&gt;
|log1p&lt;br /&gt;
|Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|log&lt;br /&gt;
|Natural logarithm (&#039;&#039;ln&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|Find highest value&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|Find lowest value&lt;br /&gt;
|-&lt;br /&gt;
|octdec&lt;br /&gt;
|Octal to decimal&lt;br /&gt;
|-&lt;br /&gt;
|pi()&lt;br /&gt;
|Get value of pi - the function does not take an argument, like in Excel.&lt;br /&gt;
|-&lt;br /&gt;
|pow (numberToRaise, NumberRaisedTo)&lt;br /&gt;
|Exponential expression&lt;br /&gt;
|-&lt;br /&gt;
|rad2deg&lt;br /&gt;
|Converts the radian number to the equivalent number in degrees&lt;br /&gt;
|-&lt;br /&gt;
|rand&lt;br /&gt;
|Generate a random integer&lt;br /&gt;
|-&lt;br /&gt;
|round&lt;br /&gt;
|Rounds a float&lt;br /&gt;
|-&lt;br /&gt;
|sin&lt;br /&gt;
|Sine -- in radians!!!  Convert your degree measurement to radians before you take the sin of it.&lt;br /&gt;
|-&lt;br /&gt;
|sinh&lt;br /&gt;
|Hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the sinh of it.&lt;br /&gt;
|-&lt;br /&gt;
|sqrt&lt;br /&gt;
|Square root&lt;br /&gt;
|-&lt;br /&gt;
|tan&lt;br /&gt;
|Tangent -- in radians!!!  Convert your degree measurement to radians before you take the tan of it.&lt;br /&gt;
|-&lt;br /&gt;
|tanh&lt;br /&gt;
|Hyperbolic tangent -- in radians!!!  Convert your degree measurement to radians before you take the tanh of it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Predefined constants==&lt;br /&gt;
Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.&lt;br /&gt;
&lt;br /&gt;
==Synchronization==&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
You could use shared wild cards to get the same values across questions in a quiz.&lt;br /&gt;
&lt;br /&gt;
A simple example will be to use the same radius in a first question asking for the perimiter of a circle of {radius}cm and a second question asking for the surface of a circle of {radius}cm.&lt;br /&gt;
&lt;br /&gt;
When the quiz will be shown to the student the two questions will shown the same {radius} value.&lt;br /&gt;
&lt;br /&gt;
However the syncronization will work &#039;&#039;&#039;ONLY&#039;&#039;&#039; if the questions are kept in the &#039;&#039;&#039;SAME&#039;&#039;&#039; category and have the &#039;&#039;&#039;SAME NUMBER OF DATASETS&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
If you need to move the synchronized questions to another category, you need to do it by editing the questions.&lt;br /&gt;
&lt;br /&gt;
(This restriction should be released by sept. 2010).&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=150923 couple questions about &amp;quot;edit datasets page&amp;quot; in calculated questions] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
&lt;br /&gt;
[[de:Berechnungsfragen]]&lt;br /&gt;
[[fr:Question calculée]]&lt;br /&gt;
[[zh:計算題]]&lt;br /&gt;
[[ja:計算問題タイプ]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=73180</id>
		<title>Calculated question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=73180"/>
		<updated>2010-06-18T08:27:30Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
Calculated questions offer a way to create individual numerical questions by the use of wildcards  (i.e &#039;&#039;&#039;{x}&#039;&#039;&#039; , &#039;&#039;&#039;{y}&#039;&#039;&#039;) that are substituted with random values when the quiz is taken.&lt;br /&gt;
 &lt;br /&gt;
For example, if you want to create a large number of &#039;&#039;&#039;&amp;quot;Calculate the area of a rectangle&amp;quot;&#039;&#039;&#039; problems to drill your students, you could create a question with two wildcards (i.e. &#039;&#039;&#039;{base}&#039;&#039;&#039;, &#039;&#039;&#039;{height}&#039;&#039;&#039;) and put in the &amp;quot;&#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039;&amp;quot; input field  &#039;&#039;&#039;{base}&#039;&#039;&#039; * &#039;&#039;&#039;{height}&#039;&#039;&#039; ( * being the multiplication sign ).&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039; {base}*{height}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
When a student takes the test, Moodle will randomly select values for &#039;&#039;&#039;{base}&#039;&#039;&#039; and &#039;&#039;&#039;{height}&#039;&#039;&#039; and grade the response using the result of the &#039;&#039;&#039;Correct Answer Formula&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
The test will very rarely appear the same way twice.&lt;br /&gt;
&lt;br /&gt;
== Is this really the question type for you? ==&lt;br /&gt;
The main purpose of the calculated question is to create multiple versions of a question with different numerical values. This means you must have &#039;&#039;&#039;at least one&#039;&#039;&#039; wildcard in one of the answers.&lt;br /&gt;
 &lt;br /&gt;
If you don&#039;t need a random element, use the [[Numerical question type]] instead.&lt;br /&gt;
&lt;br /&gt;
==Wildcards and datasets==&lt;br /&gt;
&lt;br /&gt;
When Moodle delivers a Calculated question to the student, the wildcards are replaced with randomly-selected values. However, these values are not completely random - rather, they are randomly selected from a pre-defined &#039;&#039;dataset&#039;&#039; of possible values. This allows you some control over the possible values chosen - for example, in order to make sure the numbers are realistic.&lt;br /&gt;
&lt;br /&gt;
These datasets can be &#039;&#039;private&#039;&#039; or &#039;&#039;shared&#039;&#039; - private datasets are used by one wildcard within one calculated question; shared datasets are used by one wildcard within all calculated questions that use it.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
To create (or modify) a calculated question there are three pages to work through. The instructions below take you through the pages, step by step:&lt;br /&gt;
&lt;br /&gt;
===Page 1. Editing a Calculated question ===&lt;br /&gt;
&lt;br /&gt;
#Select the question &#039;&#039;&#039;category&#039;&#039;&#039;&lt;br /&gt;
#Any shared wildcards for this category are listed beneath. If you change category, you&#039;ll need to click the &amp;quot;Update the category&amp;quot; button to refresh this list. There may not be any shared wildcards yet - if not, you can create them later if you wish.&lt;br /&gt;
#Give the question a descriptive &#039;&#039;&#039;name&#039;&#039;&#039; - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the &#039;&#039;&#039;question text&#039;&#039;&#039;. This should be the question you want the student to answer, and it must include all the information they need to calculate an answer. Therefore it must contain at least one wildcard, inside curly braces. For example, if you wanted the student to sum numbers A and B, the question text might read: &amp;quot;What is {A} + {B}?&amp;quot;&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices. If you want more control over how the image appears, include it in the question text above, using the HTML editor.&lt;br /&gt;
#Set the &#039;&#039;&#039;default question grade&#039;&#039;&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;&#039;&#039;Penalty factor&#039;&#039;&#039; (see [[Calculated_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#&#039;&#039;Moodle 1.7+:&#039;&#039; If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Next add the &#039;&#039;&#039;formula for the answer&#039;&#039;&#039;. This formula must contain at least the wildcards that appear in the question text. See [[Calculated_question_type#Correct_answer_formula_syntax|Correct answer formula syntax]] for further details.&lt;br /&gt;
# Choose the &#039;&#039;&#039;grade&#039;&#039;&#039; that the student will get for this question if they give this answer. This should be a percentage of the total marks available. For example, you could give 100% for a correct answer, and 50% for an answer that is nearly right. &#039;&#039;&#039;One of the answers must have a 100% grade&#039;&#039;&#039;.&lt;br /&gt;
#Determine the &#039;&#039;&#039;tolerance&#039;&#039;&#039; for error that you will accept in the answer. The tolerance and tolerance type settings combine to give a range of acceptable scores. So, if tolerance = t, correct answer = x and the difference between the user&#039;s answer and the correct answer is dx, then the tolerance types are as follows:&lt;br /&gt;
##Nominal - mark correct if dx &amp;lt;= t&lt;br /&gt;
##Relative - mark correct if dx / x &amp;lt;= t&lt;br /&gt;
##Geometric - mark correct if dx² / x² &amp;lt;= t²&lt;br /&gt;
# The next 2 settings, &amp;quot;Correct answer shows&amp;quot; and &amp;quot;Format&amp;quot; determine the &#039;&#039;&#039;precision&#039;&#039;&#039; of the answer. Use these to select the number of decimal places or significant figures you want to use.&lt;br /&gt;
# Add some &#039;&#039;&#039;feedback&#039;&#039;&#039; which the student will see if they enter this answer.&lt;br /&gt;
# You can specify as many answer formulae as you like - click &amp;quot;Add another answer blank&amp;quot; to add more.&lt;br /&gt;
# You can also specify units for the answers. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. If you add more than one unit, you can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
# Finally (!) you can click &amp;quot;Next page&amp;quot; to save what you&#039;ve done and move on. If you are editing an existing question, you can click &amp;quot;Next page (new question)&amp;quot; to create a completely new question based on an existing one.&lt;br /&gt;
&lt;br /&gt;
==== Penalty factor ====&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
===Tolerance===&lt;br /&gt;
&lt;br /&gt;
As for numerical questions it is possible to allow a margin within which all responses are accepted as correct. The &amp;quot;Tolerance&amp;quot; field is used for this. However, there are three different types of tolerances. These are Relative, Nominal and Geometric. If we say that the correct answer at quiz time is calculated to 200 and the tolerance is set to 0.5 then the different tolerance types work like this:&lt;br /&gt;
&lt;br /&gt;
Relative: A tolerance interval is calculated by multiplying the correct answer with 0.5, ie in this case we get 100 so for this tolerance the correct response must be between 100 and 300. (200 ± 100)&lt;br /&gt;
This is useful if the magnitude of the correct answer can differ greatly between different wildcard values.&lt;br /&gt;
&lt;br /&gt;
Nominal: This is the simplest tolerance type but not very powerful. The correct response must be between 199.5 and 200.5 (200 ± 0.5)&lt;br /&gt;
This tolerance type can be useful if the differences between different correct answers are small.&lt;br /&gt;
&lt;br /&gt;
Geometric: The upper limit of the tolerance interval is calculated as 200 + 0.5*200 and is the same as for the relative case. The lower limit is calculated as 200/(1 + 0.5). The correct response must then be between 133.33 and 300.&lt;br /&gt;
This is useful for complex calculation that must have great tolerances where relative tolerances of 1 or more would be used for the upper limit but clearly not acceptable for the lower limit as it would make zero a correct answer for all cases.&lt;br /&gt;
&lt;br /&gt;
The field Significant Figures does only relate to how the correct answer should be presented in the review or the reports. Examples: If it is set to 3 then the correct answer 13.333 would be presented as 13.3; 1236 would be presented as 1240; 23 would be presented as 23.0 etc. &lt;br /&gt;
&lt;br /&gt;
===Page 2. Choose dataset properties ===&lt;br /&gt;
&lt;br /&gt;
Each wildcard that you specify in the answer formula must have an associated set of possible values - this is its &#039;&#039;dataset&#039;&#039;. Each of the wildcards is listed on this page along with a choice of dataset:&lt;br /&gt;
*&#039;&#039;&#039;private&#039;&#039;&#039; i.e. only used by this question&lt;br /&gt;
*&#039;&#039;&#039;shared&#039;&#039;&#039; i.e shared with other calculated questions in the same category&lt;br /&gt;
&lt;br /&gt;
Using a shared dataset can save time when you are creating a lot of similar calculated questions.&lt;br /&gt;
&lt;br /&gt;
If there is anything in the question text that looks like a wildcard, but does not appear in any of the answer formulae, you can specify whether or not this is meant to be a wildcard. If it is, you can choose whether it should use a private or shared dataset.&lt;br /&gt;
&lt;br /&gt;
To continue, simply choose your preferred dataset for each wildcard, then click &amp;quot;Next Page&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Page 3. Edit the datasets ===&lt;br /&gt;
&lt;br /&gt;
Now we need to create the set of possible values that each wildcard can take. &#039;&#039;Warning&#039;&#039; - this page is a bit confusing!&lt;br /&gt;
&lt;br /&gt;
There are two ways of creating values - you can type them in yourself and add them to the list, or you can have Moodle generate them for you.&lt;br /&gt;
&lt;br /&gt;
==== Adding/deleting your own values ====&lt;br /&gt;
&lt;br /&gt;
Adding individual values to the list is easy:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Param&#039; field for each wildcard, enter the value you want&lt;br /&gt;
# Scroll down to the &#039;Add&#039; section and click the Add button (leaving the number of items set to 1)&lt;br /&gt;
# Repeat the above steps as many times as necessary (the maximum number of items is 100)&lt;br /&gt;
&lt;br /&gt;
To delete values from the list:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Delete&#039; section, select the number of items to delete&lt;br /&gt;
# Click the Delete button&lt;br /&gt;
&lt;br /&gt;
==== Letting Moodle create values ====&lt;br /&gt;
&lt;br /&gt;
# Start with the &amp;quot;Range of Values&amp;quot; fields, and enter the lower and upper limits for the values you would accept&lt;br /&gt;
# Choose a number of decimal places for the value&lt;br /&gt;
# Choose the distribution of values between the limits - &#039;uniform&#039; means any value between the limits is equally likely to be generated; &#039;loguniform&#039; means that values towards the lower limit are more likely.&lt;br /&gt;
# Now move down to the &#039;Add&#039; section and click on &amp;quot;force regeneration&amp;quot;&lt;br /&gt;
# In the menu next to the Add button, choose the number of sets of random values (items) you wish to add to the list. (Note that the maximum total number of items in your list is 100.)&lt;br /&gt;
# Finally, click Add to append the new values to the list&lt;br /&gt;
# &#039;&#039;&#039;Note:&#039;&#039;&#039; If you want more control over the items that Moodle adds, you can do them one at a time and preview the values before you add them. Click the &amp;quot;Get New Item to Add&amp;quot; button to make Moodle generate new values in the &amp;quot;Item to Add&amp;quot; section at the top. If you like them, click &amp;quot;Add&amp;quot; for 1 item; if not, click &amp;quot;Get New Item to Add&amp;quot; again to get new values.&lt;br /&gt;
&lt;br /&gt;
==== Finishing off ====&lt;br /&gt;
&lt;br /&gt;
Once your list of items (values) is complete, you are finished. It&#039;s up to you how many values you add - the more values you add, the more a question can be used by the students without them seeing the same values repeatedly.&lt;br /&gt;
&lt;br /&gt;
Note that if you delete values from the list, you can put them back again. Change the &amp;quot;Next Item to Add&amp;quot; option to &amp;quot;reuse previous value if available&amp;quot;, then the next time you add items, Moodle will restore your previously-deleted items from the dataset. &lt;br /&gt;
&lt;br /&gt;
Once your list of values is complete, you can click &#039;Save changes&#039; to finish.&lt;br /&gt;
&lt;br /&gt;
==== What does the &#039;Update the datasets parameters&#039; button do? ====&lt;br /&gt;
&lt;br /&gt;
As far as I can tell, it has the same function as the &amp;quot;Get New Item to Add&amp;quot; button, i.e. it generates a new set of values and displays them in the &amp;quot;Item to Add&amp;quot; section. However, it is less conveniently placed that that button, so it is probably best ignored.&lt;br /&gt;
&lt;br /&gt;
==Correct answer formula syntax==&lt;br /&gt;
 &lt;br /&gt;
=== DO NOT PUT THE = sign in the formula. ===&lt;br /&gt;
 &lt;br /&gt;
* In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.&lt;br /&gt;
 If more than one correct answer formula input field are displayed when editing, &lt;br /&gt;
 your site has the multiple answer feature. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As a general rule, write these formulas like you would in a calculator e.g. &amp;lt;code&amp;gt;3 + 5 * sin(3/{x})&amp;lt;/code&amp;gt; A notable exception is exponentiation, where x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; cannot be entered as &amp;lt;code&amp;gt;{x}^3&amp;lt;/code&amp;gt;, but instead should be entered as &amp;lt;code&amp;gt;pow({x}, 3)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Each function&#039;s placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter &amp;lt;code&amp;gt;sin({a}) + cos({b}*2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* It&#039;s usually better to have too many parentheses (brackets) than too few.  The server won&#039;t care, and the more specific you are about what you mean, the more likely it will like your complex formulas.&lt;br /&gt;
* There is no implicit multiplication.  To you, the human editor, &amp;quot;5(23)&amp;quot; or &amp;quot;5x&amp;quot; may seem perfectly obvious.  To the server doing the math, it&#039;s crazy talk and won&#039;t be understood.  Always use the &amp;quot;*&amp;quot; for multiplication.&lt;br /&gt;
* Any special mathematical function must have parentheses around its values.  Take the sine function in the first bullet point for instance.  Notice that the &#039;&#039;3 / x&#039;&#039; is wrapped in parentheses (brackets)--this is so the server can understand it properly.  Without those parentheses, the server won&#039;t know if you mean &amp;quot;(sin 3) / x&amp;quot; or &amp;quot;sin (3 / x)&amp;quot; and will reject the entire formula accordingly.&lt;br /&gt;
&lt;br /&gt;
==Available functions==&lt;br /&gt;
&lt;br /&gt;
Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;97%&amp;quot; border=&amp;quot;1px&amp;quot;&lt;br /&gt;
!Function&lt;br /&gt;
!Explanation&lt;br /&gt;
|-&lt;br /&gt;
|abs&lt;br /&gt;
|Absolute value&lt;br /&gt;
|-&lt;br /&gt;
|acos&lt;br /&gt;
|Arc cosine -- in radians!!!  Convert your degree measurement to radians before you take the acos of it.&lt;br /&gt;
|-&lt;br /&gt;
|acosh&lt;br /&gt;
|Inverse hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the acosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|asin&lt;br /&gt;
|Arc sine -- in radians!!!  Convert your degree measurement to radians before you take the asin of it.&lt;br /&gt;
|-&lt;br /&gt;
|asinh&lt;br /&gt;
|Inverse hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the asing of it.&lt;br /&gt;
|-&lt;br /&gt;
|atan2&lt;br /&gt;
|Arc tangent of two variables -- pass in two values like (x, y), and you&#039;ll get the atah(y/x), adjusted to the proper quadrant.&lt;br /&gt;
|-&lt;br /&gt;
|atan&lt;br /&gt;
|Arc tangent -- in radians!!!  Convert your degree measurement to radians before you take the atan of it.&lt;br /&gt;
|-&lt;br /&gt;
|atanh&lt;br /&gt;
|Inverse hyperbolic tangent&lt;br /&gt;
|-&lt;br /&gt;
|bindec&lt;br /&gt;
|Binary to decimal&lt;br /&gt;
|-&lt;br /&gt;
|ceil&lt;br /&gt;
|Round fractions up&lt;br /&gt;
|-&lt;br /&gt;
|cos&lt;br /&gt;
|Cosine -- in radians!!!  Convert your degree measurement to radians before you take the cos of it.&lt;br /&gt;
|-&lt;br /&gt;
|cosh&lt;br /&gt;
|Hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the cosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|decbin&lt;br /&gt;
|Decimal to binary&lt;br /&gt;
|-&lt;br /&gt;
|decoct&lt;br /&gt;
|Decimal to octal&lt;br /&gt;
|-&lt;br /&gt;
|deg2rad&lt;br /&gt;
|Converts the number in degrees to the radian equivalent&lt;br /&gt;
|-&lt;br /&gt;
|exp&lt;br /&gt;
|Calculates the exponent of e&lt;br /&gt;
|-&lt;br /&gt;
|expm1&lt;br /&gt;
|Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|floor&lt;br /&gt;
|Round fractions down&lt;br /&gt;
|-&lt;br /&gt;
|fmod&lt;br /&gt;
|Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.&lt;br /&gt;
|-&lt;br /&gt;
|is_finite&lt;br /&gt;
|Finds whether a value is a legal finite number&lt;br /&gt;
|-&lt;br /&gt;
|is_infinite&lt;br /&gt;
|Finds whether a value is infinite&lt;br /&gt;
|-&lt;br /&gt;
|is_nan&lt;br /&gt;
|Finds whether a value is not a number&lt;br /&gt;
|-&lt;br /&gt;
|log10&lt;br /&gt;
|Base-10 logarithm&lt;br /&gt;
|-&lt;br /&gt;
|log1p&lt;br /&gt;
|Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|log&lt;br /&gt;
|Natural logarithm (&#039;&#039;ln&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|Find highest value&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|Find lowest value&lt;br /&gt;
|-&lt;br /&gt;
|octdec&lt;br /&gt;
|Octal to decimal&lt;br /&gt;
|-&lt;br /&gt;
|pi()&lt;br /&gt;
|Get value of pi - the function does not take an argument, like in Excel.&lt;br /&gt;
|-&lt;br /&gt;
|pow (numberToRaise, NumberRaisedTo)&lt;br /&gt;
|Exponential expression&lt;br /&gt;
|-&lt;br /&gt;
|rad2deg&lt;br /&gt;
|Converts the radian number to the equivalent number in degrees&lt;br /&gt;
|-&lt;br /&gt;
|rand&lt;br /&gt;
|Generate a random integer&lt;br /&gt;
|-&lt;br /&gt;
|round&lt;br /&gt;
|Rounds a float&lt;br /&gt;
|-&lt;br /&gt;
|sin&lt;br /&gt;
|Sine -- in radians!!!  Convert your degree measurement to radians before you take the sin of it.&lt;br /&gt;
|-&lt;br /&gt;
|sinh&lt;br /&gt;
|Hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the sinh of it.&lt;br /&gt;
|-&lt;br /&gt;
|sqrt&lt;br /&gt;
|Square root&lt;br /&gt;
|-&lt;br /&gt;
|tan&lt;br /&gt;
|Tangent -- in radians!!!  Convert your degree measurement to radians before you take the tan of it.&lt;br /&gt;
|-&lt;br /&gt;
|tanh&lt;br /&gt;
|Hyperbolic tangent -- in radians!!!  Convert your degree measurement to radians before you take the tanh of it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Predefined constants==&lt;br /&gt;
Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.&lt;br /&gt;
&lt;br /&gt;
==Synchronization==&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
You could use shared wild cards to get the same values across questions in a quiz.&lt;br /&gt;
&lt;br /&gt;
A simple example will be to use the same radius in a first question asking for the perimiter of a circle of {radius}cm and a second question asking for the surface of a circle of {radius}cm.&lt;br /&gt;
&lt;br /&gt;
When the quiz will be shown to the student the two questions will shown the same {radius} value.&lt;br /&gt;
&lt;br /&gt;
However the syncronization will work &#039;&#039;&#039;ONLY&#039;&#039;&#039; if the questions are kept in the &#039;&#039;&#039;SAME&#039;&#039;&#039; category.&lt;br /&gt;
&lt;br /&gt;
If you need to move the synchronized questions to another category, you need to do it by editing the questions.&lt;br /&gt;
&lt;br /&gt;
(This restriction should be released in sept. 2010).&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=150923 couple questions about &amp;quot;edit datasets page&amp;quot; in calculated questions] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
&lt;br /&gt;
[[de:Berechnungsfragen]]&lt;br /&gt;
[[fr:Question calculée]]&lt;br /&gt;
[[zh:計算題]]&lt;br /&gt;
[[ja:計算問題タイプ]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=73038</id>
		<title>Calculated multichoice question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=73038"/>
		<updated>2010-06-15T02:03:44Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
Calculated multichoice questions are like multichoice questions with the additonal property that the elements to select can include formula results from numeric values that are selected randomly from a set when the quiz is taken.&lt;br /&gt;
They use the same wildcards than Calculated questions and their wildcards can be shared with other Calculated multichoice or regular Calculated questions.&lt;br /&gt;
&lt;br /&gt;
The main difference is that the formula is included in the answer choice as {=...} i.e if you calculate the surface of a rectangle {={l}*{w}}.&lt;br /&gt;
&lt;br /&gt;
The value will be displayed as set by the &#039;&#039;&#039;Correct answer shows&#039;&#039;&#039; (0,1,2 etc) and &#039;&#039;&#039;Format&#039;&#039;&#039; (decimals, significant figures).&lt;br /&gt;
&lt;br /&gt;
So a Choice text could be&lt;br /&gt;
&lt;br /&gt;
The rectangle surface is {={l}*{w}} cm&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If {l} = 4,0 ,  {w} = 2,5 , &#039;&#039;&#039;Correct answer shows&#039;&#039;&#039; 1 and &#039;&#039;&#039;Format&#039;&#039;&#039; decimals&lt;br /&gt;
&lt;br /&gt;
The choice will display as&lt;br /&gt;
&lt;br /&gt;
The rectangle surface is 10.0 cm&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Handling of the wild cards is similar to the calculated question type.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=73037</id>
		<title>Calculated multichoice question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=73037"/>
		<updated>2010-06-15T01:56:27Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
Calculated multichoice questions are like multichoice questions with the additonal property that the elements to select can include formula results from numeric values that are selected randomly from a set when the quiz is taken.&lt;br /&gt;
They use the same wildcards than Calculated questions and their wildcards can be shared with other Calculated multichoice or regular Calculated questions.&lt;br /&gt;
&lt;br /&gt;
The main difference is that the formula is included in the answer choice as {=...} i.e if you calculate the surface of a rectangle {={l}*{w}}.&lt;br /&gt;
&lt;br /&gt;
The value will be displayed as set by the &#039;&#039;&#039;Correct answer shows&#039;&#039;&#039; (0,1,2 etc) and &#039;&#039;&#039;Format&#039;&#039;&#039; (decimals, significant figures).&lt;br /&gt;
&lt;br /&gt;
So a Choice text could be&lt;br /&gt;
&lt;br /&gt;
The rectangle surface is {={l}*{w}} cm&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Handling of the wild cards is similar to the calculated question type.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72381</id>
		<title>Development:File storage conversion Quiz and Questions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72381"/>
		<updated>2010-05-23T08:23:30Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Question types where nothing needs to be done */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page are some notes about what has to be done for MDL-16094.&lt;br /&gt;
&lt;br /&gt;
I have chosen to write this document with reference to database columns, with secondary mention of the editing forms where the value is edited. That determines what itemid should be used with each file area.&lt;br /&gt;
&lt;br /&gt;
I would like to review code changes before they are committed for all of this, but I can&#039;t see myself having time to do much work on this, only to help someone else do it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Assumptions==&lt;br /&gt;
&lt;br /&gt;
I believe it is the case that each HTML editor on a form has to use a separate HTML editor (otherwise copying files to and from draft areas does not work). However, for question types, I don&#039;t think that leads to the best usability.&lt;br /&gt;
&lt;br /&gt;
Similarly, each HTML editor has to have a corresponding ...format field (like questiontext, questiontextformat) even though it is stupid (from a usability point of view) for different parts of a question to use different formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Issues==&lt;br /&gt;
&lt;br /&gt;
As well as the issues implicit in the assumptions above, there is also the issue that many of the images belong to a particular question. However, whether the image should be visible to a particular user at a particular time, is a decision that can only be made by the module that is using the question. Currently there are two &#039;modules&#039; that use questions: the quiz module, and the core question preview. We probably need some sort of callback API to control the serving of files. I don&#039;t have a good solution for that, but I am very happy to talk about it.&lt;br /&gt;
&lt;br /&gt;
==The quiz==&lt;br /&gt;
&lt;br /&gt;
[[Development:Quiz database structure]]&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz.intro.&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz_feedback.feedbacktext. (The overall feedback on the quiz settings form.) If it is possible to do easily, we should replace the overall feedback boxes with HTML editors (the boxes currently accept HTML input into text fields, which is functionally complete, but sucky).&lt;br /&gt;
&lt;br /&gt;
* We need to add a feedbacktextformat column, if it has not already been done.&lt;br /&gt;
&lt;br /&gt;
* Ideally, access to overall feedback files should be controlled by the same logic as whether the feedback itself is displayed. However, I think it would be acceptable to release Moodle 2.0 without this. Just leave an open tracker issue assigned to me, and I can implement that check later.&lt;br /&gt;
&lt;br /&gt;
No other quiz_... tables have files associated with any columns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Questions==&lt;br /&gt;
&lt;br /&gt;
[[Development:Question database structure]]&lt;br /&gt;
&lt;br /&gt;
There are no fields in the &#039;question engine&#039; tables that have files. Except:&lt;br /&gt;
&lt;br /&gt;
* There should be a question_sessions.manualcommentformat column. (But manual comment should not support attached files.)&lt;br /&gt;
&lt;br /&gt;
All the issues are in the &#039;question bank&#039; part, which means the core question bank, and the all the question type plugins.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Core question bank===&lt;br /&gt;
&lt;br /&gt;
* I think that question_categories.info (which is HTML) should not have files. However, we need a question_categories.infoformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas for question.questiontext and question.generalfeedback. We also need to add the missing question.generalfeedbackformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas, and ...format columns for question_answers.answer and question_answers.feedback. (Depending on the question type, question_answers.answer may be HTML, or it may not, but where it is not, we will force the ...format value to something appropriate. Anyway, as an example, answers are HTML for multichoice and truefalse, but not for numerical or shortanswer.)&lt;br /&gt;
&lt;br /&gt;
* We must get rid of the question.image column. We need an upgrade to:&lt;br /&gt;
*# Do a database upgrade that appends an img tag to the questiontext, if the img column is not empty;&lt;br /&gt;
*# and copy the file into the right file area;&lt;br /&gt;
*# then drop the question.image column;&lt;br /&gt;
*# remove that field from all editing forms;&lt;br /&gt;
*# remove the places where the image is displayed.&lt;br /&gt;
&lt;br /&gt;
Note that all the above changes require changes to the question editing form for all question types, but hopefully that can mostly be done in the form base class.&lt;br /&gt;
&lt;br /&gt;
* Question import needs to use the file-picker.&lt;br /&gt;
&lt;br /&gt;
* Question export should be changed to put the files in an appropriate file area. I am not sure what the best file area is right now. MDL-15573&lt;br /&gt;
&lt;br /&gt;
===Question types===&lt;br /&gt;
&lt;br /&gt;
====Question types where nothing needs to be done====&lt;br /&gt;
&lt;br /&gt;
These only use the core question tables, or do not need files associated with their own tables.&lt;br /&gt;
&lt;br /&gt;
* Description&lt;br /&gt;
* Essay&lt;br /&gt;
* Missing type&lt;br /&gt;
* &#039;&#039;&#039;Numerical&#039;&#039;&#039;&lt;br /&gt;
The new 2,0 number and unit grading use a new table question_numerical_options where the instructions field is HTML which could include images.&lt;br /&gt;
&lt;br /&gt;
This table is also used by calculated and calculated simple.&lt;br /&gt;
&lt;br /&gt;
Pierre Pichet 08:11, 23 May 2010 (UTC) &lt;br /&gt;
&lt;br /&gt;
* Random&lt;br /&gt;
* Random short-answer matching&lt;br /&gt;
* Short answer&lt;br /&gt;
* True-false&lt;br /&gt;
&lt;br /&gt;
====Match====&lt;br /&gt;
&lt;br /&gt;
* question_match_sub.questiontext needs a ...format column and a file area. (answertext does not. It is displayed in a select menu.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Multiple choice====&lt;br /&gt;
&lt;br /&gt;
* correctfeedback, partiallycorrectfeedback and incorrectfeedback all need ...format columns and a file area.&lt;br /&gt;
&lt;br /&gt;
* The choice entry boxes on the editing form should be changed to HTML editors.&lt;br /&gt;
&lt;br /&gt;
====Question types I am not really sure about====&lt;br /&gt;
&lt;br /&gt;
* Calculated* - I don&#039;t really know what Pierre is doing here. I need to get my head round it.&lt;br /&gt;
&lt;br /&gt;
So here is the status of calculated in 2,0.&lt;br /&gt;
&lt;br /&gt;
The calculatedsimple is just a regular calculated that can be edited in a one page because it is not using the shared category datasets. In both on them there is no new field with image to store other than question text and answer feedback.&lt;br /&gt;
&lt;br /&gt;
The answer field is just math formula i.e. plain text.&lt;br /&gt;
&lt;br /&gt;
The multichoice calculated is a multichoice where calculated math formula can be inserted {=...} so the requirements are the same as regular multichoice.&lt;br /&gt;
&lt;br /&gt;
Regular calculated and multichoice calculated used the new table question_calculated_options although regular calculated only used the synchronize field, multichoice calculated using the other fields.&lt;br /&gt;
I prefer to use only one new table and the fields for multichoice calculated are a copy of most of the multichoice ones.&lt;br /&gt;
&lt;br /&gt;
This is a new table in 2,0 so no file conversion.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Multi-answer - probably does not need any other file areas, but the code may need fixing a bit.&lt;br /&gt;
&lt;br /&gt;
So here is the status of Multi-answer in 2,0.&lt;br /&gt;
&lt;br /&gt;
Multi-answer code is the same has in 1.9, the improvements has been on the data validation in the edit_form with additional warnings when the user modify the number or question type in the question text peculiarly when the question has attempts stored.&lt;br /&gt;
 &lt;br /&gt;
I am working on the lang strings.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==For the future==&lt;br /&gt;
&lt;br /&gt;
As in, Moodle 2.1 or later.&lt;br /&gt;
&lt;br /&gt;
* Support files in student responses and manual comments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-16094&lt;br /&gt;
* Feel free to discuss this with Tim Hunt.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72380</id>
		<title>Development:File storage conversion Quiz and Questions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72380"/>
		<updated>2010-05-23T08:21:26Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Question types I am not really sure about */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page are some notes about what has to be done for MDL-16094.&lt;br /&gt;
&lt;br /&gt;
I have chosen to write this document with reference to database columns, with secondary mention of the editing forms where the value is edited. That determines what itemid should be used with each file area.&lt;br /&gt;
&lt;br /&gt;
I would like to review code changes before they are committed for all of this, but I can&#039;t see myself having time to do much work on this, only to help someone else do it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Assumptions==&lt;br /&gt;
&lt;br /&gt;
I believe it is the case that each HTML editor on a form has to use a separate HTML editor (otherwise copying files to and from draft areas does not work). However, for question types, I don&#039;t think that leads to the best usability.&lt;br /&gt;
&lt;br /&gt;
Similarly, each HTML editor has to have a corresponding ...format field (like questiontext, questiontextformat) even though it is stupid (from a usability point of view) for different parts of a question to use different formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Issues==&lt;br /&gt;
&lt;br /&gt;
As well as the issues implicit in the assumptions above, there is also the issue that many of the images belong to a particular question. However, whether the image should be visible to a particular user at a particular time, is a decision that can only be made by the module that is using the question. Currently there are two &#039;modules&#039; that use questions: the quiz module, and the core question preview. We probably need some sort of callback API to control the serving of files. I don&#039;t have a good solution for that, but I am very happy to talk about it.&lt;br /&gt;
&lt;br /&gt;
==The quiz==&lt;br /&gt;
&lt;br /&gt;
[[Development:Quiz database structure]]&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz.intro.&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz_feedback.feedbacktext. (The overall feedback on the quiz settings form.) If it is possible to do easily, we should replace the overall feedback boxes with HTML editors (the boxes currently accept HTML input into text fields, which is functionally complete, but sucky).&lt;br /&gt;
&lt;br /&gt;
* We need to add a feedbacktextformat column, if it has not already been done.&lt;br /&gt;
&lt;br /&gt;
* Ideally, access to overall feedback files should be controlled by the same logic as whether the feedback itself is displayed. However, I think it would be acceptable to release Moodle 2.0 without this. Just leave an open tracker issue assigned to me, and I can implement that check later.&lt;br /&gt;
&lt;br /&gt;
No other quiz_... tables have files associated with any columns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Questions==&lt;br /&gt;
&lt;br /&gt;
[[Development:Question database structure]]&lt;br /&gt;
&lt;br /&gt;
There are no fields in the &#039;question engine&#039; tables that have files. Except:&lt;br /&gt;
&lt;br /&gt;
* There should be a question_sessions.manualcommentformat column. (But manual comment should not support attached files.)&lt;br /&gt;
&lt;br /&gt;
All the issues are in the &#039;question bank&#039; part, which means the core question bank, and the all the question type plugins.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Core question bank===&lt;br /&gt;
&lt;br /&gt;
* I think that question_categories.info (which is HTML) should not have files. However, we need a question_categories.infoformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas for question.questiontext and question.generalfeedback. We also need to add the missing question.generalfeedbackformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas, and ...format columns for question_answers.answer and question_answers.feedback. (Depending on the question type, question_answers.answer may be HTML, or it may not, but where it is not, we will force the ...format value to something appropriate. Anyway, as an example, answers are HTML for multichoice and truefalse, but not for numerical or shortanswer.)&lt;br /&gt;
&lt;br /&gt;
* We must get rid of the question.image column. We need an upgrade to:&lt;br /&gt;
*# Do a database upgrade that appends an img tag to the questiontext, if the img column is not empty;&lt;br /&gt;
*# and copy the file into the right file area;&lt;br /&gt;
*# then drop the question.image column;&lt;br /&gt;
*# remove that field from all editing forms;&lt;br /&gt;
*# remove the places where the image is displayed.&lt;br /&gt;
&lt;br /&gt;
Note that all the above changes require changes to the question editing form for all question types, but hopefully that can mostly be done in the form base class.&lt;br /&gt;
&lt;br /&gt;
* Question import needs to use the file-picker.&lt;br /&gt;
&lt;br /&gt;
* Question export should be changed to put the files in an appropriate file area. I am not sure what the best file area is right now. MDL-15573&lt;br /&gt;
&lt;br /&gt;
===Question types===&lt;br /&gt;
&lt;br /&gt;
====Question types where nothing needs to be done====&lt;br /&gt;
&lt;br /&gt;
These only use the core question tables, or do not need files associated with their own tables.&lt;br /&gt;
&lt;br /&gt;
* Description&lt;br /&gt;
* Essay&lt;br /&gt;
* Missing type&lt;br /&gt;
* Numerical&lt;br /&gt;
The new 2,0 number and unit grading use a new table question_numerical_options where the instructions field is HTML which could include images.&lt;br /&gt;
&lt;br /&gt;
This table is also used by calculated and calculated simple.&lt;br /&gt;
&lt;br /&gt;
Pierre Pichet 08:11, 23 May 2010 (UTC) &lt;br /&gt;
&lt;br /&gt;
* Random&lt;br /&gt;
* Random short-answer matching&lt;br /&gt;
* Short answer&lt;br /&gt;
* True-false&lt;br /&gt;
&lt;br /&gt;
====Match====&lt;br /&gt;
&lt;br /&gt;
* question_match_sub.questiontext needs a ...format column and a file area. (answertext does not. It is displayed in a select menu.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Multiple choice====&lt;br /&gt;
&lt;br /&gt;
* correctfeedback, partiallycorrectfeedback and incorrectfeedback all need ...format columns and a file area.&lt;br /&gt;
&lt;br /&gt;
* The choice entry boxes on the editing form should be changed to HTML editors.&lt;br /&gt;
&lt;br /&gt;
====Question types I am not really sure about====&lt;br /&gt;
&lt;br /&gt;
* Calculated* - I don&#039;t really know what Pierre is doing here. I need to get my head round it.&lt;br /&gt;
&lt;br /&gt;
So here is the status of calculated in 2,0.&lt;br /&gt;
&lt;br /&gt;
The calculatedsimple is just a regular calculated that can be edited in a one page because it is not using the shared category datasets. In both on them there is no new field with image to store other than question text and answer feedback.&lt;br /&gt;
&lt;br /&gt;
The answer field is just math formula i.e. plain text.&lt;br /&gt;
&lt;br /&gt;
The multichoice calculated is a multichoice where calculated math formula can be inserted {=...} so the requirements are the same as regular multichoice.&lt;br /&gt;
&lt;br /&gt;
Regular calculated and multichoice calculated used the new table question_calculated_options although regular calculated only used the synchronize field, multichoice calculated using the other fields.&lt;br /&gt;
I prefer to use only one new table and the fields for multichoice calculated are a copy of most of the multichoice ones.&lt;br /&gt;
&lt;br /&gt;
This is a new table in 2,0 so no file conversion.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Multi-answer - probably does not need any other file areas, but the code may need fixing a bit.&lt;br /&gt;
&lt;br /&gt;
So here is the status of Multi-answer in 2,0.&lt;br /&gt;
&lt;br /&gt;
Multi-answer code is the same has in 1.9, the improvements has been on the data validation in the edit_form with additional warnings when the user modify the number or question type in the question text peculiarly when the question has attempts stored.&lt;br /&gt;
 &lt;br /&gt;
I am working on the lang strings.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==For the future==&lt;br /&gt;
&lt;br /&gt;
As in, Moodle 2.1 or later.&lt;br /&gt;
&lt;br /&gt;
* Support files in student responses and manual comments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-16094&lt;br /&gt;
* Feel free to discuss this with Tim Hunt.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72379</id>
		<title>Development:File storage conversion Quiz and Questions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72379"/>
		<updated>2010-05-23T08:20:59Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Question types where nothing needs to be done */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page are some notes about what has to be done for MDL-16094.&lt;br /&gt;
&lt;br /&gt;
I have chosen to write this document with reference to database columns, with secondary mention of the editing forms where the value is edited. That determines what itemid should be used with each file area.&lt;br /&gt;
&lt;br /&gt;
I would like to review code changes before they are committed for all of this, but I can&#039;t see myself having time to do much work on this, only to help someone else do it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Assumptions==&lt;br /&gt;
&lt;br /&gt;
I believe it is the case that each HTML editor on a form has to use a separate HTML editor (otherwise copying files to and from draft areas does not work). However, for question types, I don&#039;t think that leads to the best usability.&lt;br /&gt;
&lt;br /&gt;
Similarly, each HTML editor has to have a corresponding ...format field (like questiontext, questiontextformat) even though it is stupid (from a usability point of view) for different parts of a question to use different formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Issues==&lt;br /&gt;
&lt;br /&gt;
As well as the issues implicit in the assumptions above, there is also the issue that many of the images belong to a particular question. However, whether the image should be visible to a particular user at a particular time, is a decision that can only be made by the module that is using the question. Currently there are two &#039;modules&#039; that use questions: the quiz module, and the core question preview. We probably need some sort of callback API to control the serving of files. I don&#039;t have a good solution for that, but I am very happy to talk about it.&lt;br /&gt;
&lt;br /&gt;
==The quiz==&lt;br /&gt;
&lt;br /&gt;
[[Development:Quiz database structure]]&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz.intro.&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz_feedback.feedbacktext. (The overall feedback on the quiz settings form.) If it is possible to do easily, we should replace the overall feedback boxes with HTML editors (the boxes currently accept HTML input into text fields, which is functionally complete, but sucky).&lt;br /&gt;
&lt;br /&gt;
* We need to add a feedbacktextformat column, if it has not already been done.&lt;br /&gt;
&lt;br /&gt;
* Ideally, access to overall feedback files should be controlled by the same logic as whether the feedback itself is displayed. However, I think it would be acceptable to release Moodle 2.0 without this. Just leave an open tracker issue assigned to me, and I can implement that check later.&lt;br /&gt;
&lt;br /&gt;
No other quiz_... tables have files associated with any columns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Questions==&lt;br /&gt;
&lt;br /&gt;
[[Development:Question database structure]]&lt;br /&gt;
&lt;br /&gt;
There are no fields in the &#039;question engine&#039; tables that have files. Except:&lt;br /&gt;
&lt;br /&gt;
* There should be a question_sessions.manualcommentformat column. (But manual comment should not support attached files.)&lt;br /&gt;
&lt;br /&gt;
All the issues are in the &#039;question bank&#039; part, which means the core question bank, and the all the question type plugins.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Core question bank===&lt;br /&gt;
&lt;br /&gt;
* I think that question_categories.info (which is HTML) should not have files. However, we need a question_categories.infoformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas for question.questiontext and question.generalfeedback. We also need to add the missing question.generalfeedbackformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas, and ...format columns for question_answers.answer and question_answers.feedback. (Depending on the question type, question_answers.answer may be HTML, or it may not, but where it is not, we will force the ...format value to something appropriate. Anyway, as an example, answers are HTML for multichoice and truefalse, but not for numerical or shortanswer.)&lt;br /&gt;
&lt;br /&gt;
* We must get rid of the question.image column. We need an upgrade to:&lt;br /&gt;
*# Do a database upgrade that appends an img tag to the questiontext, if the img column is not empty;&lt;br /&gt;
*# and copy the file into the right file area;&lt;br /&gt;
*# then drop the question.image column;&lt;br /&gt;
*# remove that field from all editing forms;&lt;br /&gt;
*# remove the places where the image is displayed.&lt;br /&gt;
&lt;br /&gt;
Note that all the above changes require changes to the question editing form for all question types, but hopefully that can mostly be done in the form base class.&lt;br /&gt;
&lt;br /&gt;
* Question import needs to use the file-picker.&lt;br /&gt;
&lt;br /&gt;
* Question export should be changed to put the files in an appropriate file area. I am not sure what the best file area is right now. MDL-15573&lt;br /&gt;
&lt;br /&gt;
===Question types===&lt;br /&gt;
&lt;br /&gt;
====Question types where nothing needs to be done====&lt;br /&gt;
&lt;br /&gt;
These only use the core question tables, or do not need files associated with their own tables.&lt;br /&gt;
&lt;br /&gt;
* Description&lt;br /&gt;
* Essay&lt;br /&gt;
* Missing type&lt;br /&gt;
* Numerical&lt;br /&gt;
The new 2,0 number and unit grading use a new table question_numerical_options where the instructions field is HTML which could include images.&lt;br /&gt;
&lt;br /&gt;
This table is also used by calculated and calculated simple.&lt;br /&gt;
&lt;br /&gt;
Pierre Pichet 08:11, 23 May 2010 (UTC) &lt;br /&gt;
&lt;br /&gt;
* Random&lt;br /&gt;
* Random short-answer matching&lt;br /&gt;
* Short answer&lt;br /&gt;
* True-false&lt;br /&gt;
&lt;br /&gt;
====Match====&lt;br /&gt;
&lt;br /&gt;
* question_match_sub.questiontext needs a ...format column and a file area. (answertext does not. It is displayed in a select menu.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Multiple choice====&lt;br /&gt;
&lt;br /&gt;
* correctfeedback, partiallycorrectfeedback and incorrectfeedback all need ...format columns and a file area.&lt;br /&gt;
&lt;br /&gt;
* The choice entry boxes on the editing form should be changed to HTML editors.&lt;br /&gt;
&lt;br /&gt;
====Question types I am not really sure about====&lt;br /&gt;
&lt;br /&gt;
* Calculated* - I don&#039;t really know what Pierre is doing here. I need to get my head round it.&lt;br /&gt;
&lt;br /&gt;
So here is the status of calculated in 2,0.&lt;br /&gt;
&lt;br /&gt;
The calculatedsimple is just a regular calculated that can be edited in a one page because it is not using the shared category datasets. In both on them there is no new field with image to store other than question text and answer feedback.&lt;br /&gt;
&lt;br /&gt;
The answer field is just math formula i.e. plain text.&lt;br /&gt;
&lt;br /&gt;
The multichoice calculated is a multichoice where calculated math formula can be inserted {=...} so the requirements are the same as regular multichoice.&lt;br /&gt;
&lt;br /&gt;
Regular calculated and multichoice calculated used the new table question_calculated_options although regular calculated only used the synchronize field, multichoice calculated using the other fields.&lt;br /&gt;
I prefer to use only one new table and the fields for multichoice calculated are a copy of most of the multichoice ones.&lt;br /&gt;
&lt;br /&gt;
This is a new table in 2,0 so no file conversion.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Multi-answer - probably does not need any other file areas, but the code may need fixing a bit.&lt;br /&gt;
&lt;br /&gt;
So here is the status of Multi-answer in 2,0.&lt;br /&gt;
&lt;br /&gt;
Multi-answer code is the same has in 1.9, the improvements has been on the data validation in the edit_form with additional warnings when the user modify the number or question type in the question text peculiarly when the question has attempts stored.&lt;br /&gt;
 &lt;br /&gt;
I am working on the lang strings.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
* Numerical&lt;br /&gt;
&lt;br /&gt;
The new 2,0 number and unit grading use a new table question_numerical_options where the instructions field is HTML which could include images. &lt;br /&gt;
&lt;br /&gt;
This table is also used by calculated and calculated simple.&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:11, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==For the future==&lt;br /&gt;
&lt;br /&gt;
As in, Moodle 2.1 or later.&lt;br /&gt;
&lt;br /&gt;
* Support files in student responses and manual comments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-16094&lt;br /&gt;
* Feel free to discuss this with Tim Hunt.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72378</id>
		<title>Development:File storage conversion Quiz and Questions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72378"/>
		<updated>2010-05-23T08:13:29Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Question types I am not really sure about */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page are some notes about what has to be done for MDL-16094.&lt;br /&gt;
&lt;br /&gt;
I have chosen to write this document with reference to database columns, with secondary mention of the editing forms where the value is edited. That determines what itemid should be used with each file area.&lt;br /&gt;
&lt;br /&gt;
I would like to review code changes before they are committed for all of this, but I can&#039;t see myself having time to do much work on this, only to help someone else do it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Assumptions==&lt;br /&gt;
&lt;br /&gt;
I believe it is the case that each HTML editor on a form has to use a separate HTML editor (otherwise copying files to and from draft areas does not work). However, for question types, I don&#039;t think that leads to the best usability.&lt;br /&gt;
&lt;br /&gt;
Similarly, each HTML editor has to have a corresponding ...format field (like questiontext, questiontextformat) even though it is stupid (from a usability point of view) for different parts of a question to use different formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Issues==&lt;br /&gt;
&lt;br /&gt;
As well as the issues implicit in the assumptions above, there is also the issue that many of the images belong to a particular question. However, whether the image should be visible to a particular user at a particular time, is a decision that can only be made by the module that is using the question. Currently there are two &#039;modules&#039; that use questions: the quiz module, and the core question preview. We probably need some sort of callback API to control the serving of files. I don&#039;t have a good solution for that, but I am very happy to talk about it.&lt;br /&gt;
&lt;br /&gt;
==The quiz==&lt;br /&gt;
&lt;br /&gt;
[[Development:Quiz database structure]]&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz.intro.&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz_feedback.feedbacktext. (The overall feedback on the quiz settings form.) If it is possible to do easily, we should replace the overall feedback boxes with HTML editors (the boxes currently accept HTML input into text fields, which is functionally complete, but sucky).&lt;br /&gt;
&lt;br /&gt;
* We need to add a feedbacktextformat column, if it has not already been done.&lt;br /&gt;
&lt;br /&gt;
* Ideally, access to overall feedback files should be controlled by the same logic as whether the feedback itself is displayed. However, I think it would be acceptable to release Moodle 2.0 without this. Just leave an open tracker issue assigned to me, and I can implement that check later.&lt;br /&gt;
&lt;br /&gt;
No other quiz_... tables have files associated with any columns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Questions==&lt;br /&gt;
&lt;br /&gt;
[[Development:Question database structure]]&lt;br /&gt;
&lt;br /&gt;
There are no fields in the &#039;question engine&#039; tables that have files. Except:&lt;br /&gt;
&lt;br /&gt;
* There should be a question_sessions.manualcommentformat column. (But manual comment should not support attached files.)&lt;br /&gt;
&lt;br /&gt;
All the issues are in the &#039;question bank&#039; part, which means the core question bank, and the all the question type plugins.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Core question bank===&lt;br /&gt;
&lt;br /&gt;
* I think that question_categories.info (which is HTML) should not have files. However, we need a question_categories.infoformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas for question.questiontext and question.generalfeedback. We also need to add the missing question.generalfeedbackformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas, and ...format columns for question_answers.answer and question_answers.feedback. (Depending on the question type, question_answers.answer may be HTML, or it may not, but where it is not, we will force the ...format value to something appropriate. Anyway, as an example, answers are HTML for multichoice and truefalse, but not for numerical or shortanswer.)&lt;br /&gt;
&lt;br /&gt;
* We must get rid of the question.image column. We need an upgrade to:&lt;br /&gt;
*# Do a database upgrade that appends an img tag to the questiontext, if the img column is not empty;&lt;br /&gt;
*# and copy the file into the right file area;&lt;br /&gt;
*# then drop the question.image column;&lt;br /&gt;
*# remove that field from all editing forms;&lt;br /&gt;
*# remove the places where the image is displayed.&lt;br /&gt;
&lt;br /&gt;
Note that all the above changes require changes to the question editing form for all question types, but hopefully that can mostly be done in the form base class.&lt;br /&gt;
&lt;br /&gt;
* Question import needs to use the file-picker.&lt;br /&gt;
&lt;br /&gt;
* Question export should be changed to put the files in an appropriate file area. I am not sure what the best file area is right now. MDL-15573&lt;br /&gt;
&lt;br /&gt;
===Question types===&lt;br /&gt;
&lt;br /&gt;
====Question types where nothing needs to be done====&lt;br /&gt;
&lt;br /&gt;
These only use the core question tables, or do not need files associated with their own tables.&lt;br /&gt;
&lt;br /&gt;
* Description&lt;br /&gt;
* Essay&lt;br /&gt;
* Missing type&lt;br /&gt;
* Numerical&lt;br /&gt;
* Random&lt;br /&gt;
* Random short-answer matching&lt;br /&gt;
* Short answer&lt;br /&gt;
* True-false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Match====&lt;br /&gt;
&lt;br /&gt;
* question_match_sub.questiontext needs a ...format column and a file area. (answertext does not. It is displayed in a select menu.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Multiple choice====&lt;br /&gt;
&lt;br /&gt;
* correctfeedback, partiallycorrectfeedback and incorrectfeedback all need ...format columns and a file area.&lt;br /&gt;
&lt;br /&gt;
* The choice entry boxes on the editing form should be changed to HTML editors.&lt;br /&gt;
&lt;br /&gt;
====Question types I am not really sure about====&lt;br /&gt;
&lt;br /&gt;
* Calculated* - I don&#039;t really know what Pierre is doing here. I need to get my head round it.&lt;br /&gt;
&lt;br /&gt;
So here is the status of calculated in 2,0.&lt;br /&gt;
&lt;br /&gt;
The calculatedsimple is just a regular calculated that can be edited in a one page because it is not using the shared category datasets. In both on them there is no new field with image to store other than question text and answer feedback.&lt;br /&gt;
&lt;br /&gt;
The answer field is just math formula i.e. plain text.&lt;br /&gt;
&lt;br /&gt;
The multichoice calculated is a multichoice where calculated math formula can be inserted {=...} so the requirements are the same as regular multichoice.&lt;br /&gt;
&lt;br /&gt;
Regular calculated and multichoice calculated used the new table question_calculated_options although regular calculated only used the synchronize field, multichoice calculated using the other fields.&lt;br /&gt;
I prefer to use only one new table and the fields for multichoice calculated are a copy of most of the multichoice ones.&lt;br /&gt;
&lt;br /&gt;
This is a new table in 2,0 so no file conversion.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Multi-answer - probably does not need any other file areas, but the code may need fixing a bit.&lt;br /&gt;
&lt;br /&gt;
So here is the status of Multi-answer in 2,0.&lt;br /&gt;
&lt;br /&gt;
Multi-answer code is the same has in 1.9, the improvements has been on the data validation in the edit_form with additional warnings when the user modify the number or question type in the question text peculiarly when the question has attempts stored.&lt;br /&gt;
 &lt;br /&gt;
I am working on the lang strings.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
* Numerical&lt;br /&gt;
&lt;br /&gt;
The new 2,0 number and unit grading use a new table question_numerical_options where the instructions field is HTML which could include images. &lt;br /&gt;
&lt;br /&gt;
This table is also used by calculated and calculated simple.&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:11, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==For the future==&lt;br /&gt;
&lt;br /&gt;
As in, Moodle 2.1 or later.&lt;br /&gt;
&lt;br /&gt;
* Support files in student responses and manual comments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-16094&lt;br /&gt;
* Feel free to discuss this with Tim Hunt.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72377</id>
		<title>Development:File storage conversion Quiz and Questions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72377"/>
		<updated>2010-05-23T08:11:52Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Question types I am not really sure about */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page are some notes about what has to be done for MDL-16094.&lt;br /&gt;
&lt;br /&gt;
I have chosen to write this document with reference to database columns, with secondary mention of the editing forms where the value is edited. That determines what itemid should be used with each file area.&lt;br /&gt;
&lt;br /&gt;
I would like to review code changes before they are committed for all of this, but I can&#039;t see myself having time to do much work on this, only to help someone else do it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Assumptions==&lt;br /&gt;
&lt;br /&gt;
I believe it is the case that each HTML editor on a form has to use a separate HTML editor (otherwise copying files to and from draft areas does not work). However, for question types, I don&#039;t think that leads to the best usability.&lt;br /&gt;
&lt;br /&gt;
Similarly, each HTML editor has to have a corresponding ...format field (like questiontext, questiontextformat) even though it is stupid (from a usability point of view) for different parts of a question to use different formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Issues==&lt;br /&gt;
&lt;br /&gt;
As well as the issues implicit in the assumptions above, there is also the issue that many of the images belong to a particular question. However, whether the image should be visible to a particular user at a particular time, is a decision that can only be made by the module that is using the question. Currently there are two &#039;modules&#039; that use questions: the quiz module, and the core question preview. We probably need some sort of callback API to control the serving of files. I don&#039;t have a good solution for that, but I am very happy to talk about it.&lt;br /&gt;
&lt;br /&gt;
==The quiz==&lt;br /&gt;
&lt;br /&gt;
[[Development:Quiz database structure]]&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz.intro.&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz_feedback.feedbacktext. (The overall feedback on the quiz settings form.) If it is possible to do easily, we should replace the overall feedback boxes with HTML editors (the boxes currently accept HTML input into text fields, which is functionally complete, but sucky).&lt;br /&gt;
&lt;br /&gt;
* We need to add a feedbacktextformat column, if it has not already been done.&lt;br /&gt;
&lt;br /&gt;
* Ideally, access to overall feedback files should be controlled by the same logic as whether the feedback itself is displayed. However, I think it would be acceptable to release Moodle 2.0 without this. Just leave an open tracker issue assigned to me, and I can implement that check later.&lt;br /&gt;
&lt;br /&gt;
No other quiz_... tables have files associated with any columns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Questions==&lt;br /&gt;
&lt;br /&gt;
[[Development:Question database structure]]&lt;br /&gt;
&lt;br /&gt;
There are no fields in the &#039;question engine&#039; tables that have files. Except:&lt;br /&gt;
&lt;br /&gt;
* There should be a question_sessions.manualcommentformat column. (But manual comment should not support attached files.)&lt;br /&gt;
&lt;br /&gt;
All the issues are in the &#039;question bank&#039; part, which means the core question bank, and the all the question type plugins.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Core question bank===&lt;br /&gt;
&lt;br /&gt;
* I think that question_categories.info (which is HTML) should not have files. However, we need a question_categories.infoformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas for question.questiontext and question.generalfeedback. We also need to add the missing question.generalfeedbackformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas, and ...format columns for question_answers.answer and question_answers.feedback. (Depending on the question type, question_answers.answer may be HTML, or it may not, but where it is not, we will force the ...format value to something appropriate. Anyway, as an example, answers are HTML for multichoice and truefalse, but not for numerical or shortanswer.)&lt;br /&gt;
&lt;br /&gt;
* We must get rid of the question.image column. We need an upgrade to:&lt;br /&gt;
*# Do a database upgrade that appends an img tag to the questiontext, if the img column is not empty;&lt;br /&gt;
*# and copy the file into the right file area;&lt;br /&gt;
*# then drop the question.image column;&lt;br /&gt;
*# remove that field from all editing forms;&lt;br /&gt;
*# remove the places where the image is displayed.&lt;br /&gt;
&lt;br /&gt;
Note that all the above changes require changes to the question editing form for all question types, but hopefully that can mostly be done in the form base class.&lt;br /&gt;
&lt;br /&gt;
* Question import needs to use the file-picker.&lt;br /&gt;
&lt;br /&gt;
* Question export should be changed to put the files in an appropriate file area. I am not sure what the best file area is right now. MDL-15573&lt;br /&gt;
&lt;br /&gt;
===Question types===&lt;br /&gt;
&lt;br /&gt;
====Question types where nothing needs to be done====&lt;br /&gt;
&lt;br /&gt;
These only use the core question tables, or do not need files associated with their own tables.&lt;br /&gt;
&lt;br /&gt;
* Description&lt;br /&gt;
* Essay&lt;br /&gt;
* Missing type&lt;br /&gt;
* Numerical&lt;br /&gt;
* Random&lt;br /&gt;
* Random short-answer matching&lt;br /&gt;
* Short answer&lt;br /&gt;
* True-false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Match====&lt;br /&gt;
&lt;br /&gt;
* question_match_sub.questiontext needs a ...format column and a file area. (answertext does not. It is displayed in a select menu.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Multiple choice====&lt;br /&gt;
&lt;br /&gt;
* correctfeedback, partiallycorrectfeedback and incorrectfeedback all need ...format columns and a file area.&lt;br /&gt;
&lt;br /&gt;
* The choice entry boxes on the editing form should be changed to HTML editors.&lt;br /&gt;
&lt;br /&gt;
====Question types I am not really sure about====&lt;br /&gt;
&lt;br /&gt;
* Calculated* - I don&#039;t really know what Pierre is doing here. I need to get my head round it.&lt;br /&gt;
&lt;br /&gt;
So here is the status of calculated in 2,0.&lt;br /&gt;
&lt;br /&gt;
The calculatedsimple is just a regular calculated that can be edited in a one page because it is not using the shared category datasets. In both on them there is no new field with image to store other than question text and answer feedback.&lt;br /&gt;
&lt;br /&gt;
The answer field is just math formula i.e. plain text.&lt;br /&gt;
&lt;br /&gt;
The multichoice calculated is a multichoice where calculated math formula can be inserted {=...} so the requirements are the same as regular multichoice.&lt;br /&gt;
&lt;br /&gt;
Regular calculated and multichoice calculated used the new table question_calculated_options although regular calculated only used the synchronize field, multichoice calculated using the other fields.&lt;br /&gt;
I prefer to use only one new table and the fields for multichoice are a copy of most of the multichoice ones.&lt;br /&gt;
&lt;br /&gt;
This is a new table in 2,0 so no file conversion.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Multi-answer - probably does not need any other file areas, but the code may need fixing a bit.&lt;br /&gt;
&lt;br /&gt;
So here is the status of Multi-answer in 2,0.&lt;br /&gt;
&lt;br /&gt;
Multi-answer code is the same has in 1.9, the improvements has been on the data validation in the edit_form with additional warnings when the user modify the number or question type in the question text peculiarly when the question has attempts stored.&lt;br /&gt;
 &lt;br /&gt;
I am working on the lang strings.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
* Numerical&lt;br /&gt;
&lt;br /&gt;
The new 2,0 number and unit grading use a new table question_numerical_options where the instructions field is HTML which could include images. &lt;br /&gt;
&lt;br /&gt;
This table is also used by calculated and calculated simple.&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:11, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==For the future==&lt;br /&gt;
&lt;br /&gt;
As in, Moodle 2.1 or later.&lt;br /&gt;
&lt;br /&gt;
* Support files in student responses and manual comments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-16094&lt;br /&gt;
* Feel free to discuss this with Tim Hunt.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72376</id>
		<title>Development:File storage conversion Quiz and Questions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Development:File_storage_conversion_Quiz_and_Questions&amp;diff=72376"/>
		<updated>2010-05-23T08:01:04Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Question types I am not really sure about */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page are some notes about what has to be done for MDL-16094.&lt;br /&gt;
&lt;br /&gt;
I have chosen to write this document with reference to database columns, with secondary mention of the editing forms where the value is edited. That determines what itemid should be used with each file area.&lt;br /&gt;
&lt;br /&gt;
I would like to review code changes before they are committed for all of this, but I can&#039;t see myself having time to do much work on this, only to help someone else do it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Assumptions==&lt;br /&gt;
&lt;br /&gt;
I believe it is the case that each HTML editor on a form has to use a separate HTML editor (otherwise copying files to and from draft areas does not work). However, for question types, I don&#039;t think that leads to the best usability.&lt;br /&gt;
&lt;br /&gt;
Similarly, each HTML editor has to have a corresponding ...format field (like questiontext, questiontextformat) even though it is stupid (from a usability point of view) for different parts of a question to use different formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Issues==&lt;br /&gt;
&lt;br /&gt;
As well as the issues implicit in the assumptions above, there is also the issue that many of the images belong to a particular question. However, whether the image should be visible to a particular user at a particular time, is a decision that can only be made by the module that is using the question. Currently there are two &#039;modules&#039; that use questions: the quiz module, and the core question preview. We probably need some sort of callback API to control the serving of files. I don&#039;t have a good solution for that, but I am very happy to talk about it.&lt;br /&gt;
&lt;br /&gt;
==The quiz==&lt;br /&gt;
&lt;br /&gt;
[[Development:Quiz database structure]]&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz.intro.&lt;br /&gt;
&lt;br /&gt;
* We need a file area for quiz_feedback.feedbacktext. (The overall feedback on the quiz settings form.) If it is possible to do easily, we should replace the overall feedback boxes with HTML editors (the boxes currently accept HTML input into text fields, which is functionally complete, but sucky).&lt;br /&gt;
&lt;br /&gt;
* We need to add a feedbacktextformat column, if it has not already been done.&lt;br /&gt;
&lt;br /&gt;
* Ideally, access to overall feedback files should be controlled by the same logic as whether the feedback itself is displayed. However, I think it would be acceptable to release Moodle 2.0 without this. Just leave an open tracker issue assigned to me, and I can implement that check later.&lt;br /&gt;
&lt;br /&gt;
No other quiz_... tables have files associated with any columns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Questions==&lt;br /&gt;
&lt;br /&gt;
[[Development:Question database structure]]&lt;br /&gt;
&lt;br /&gt;
There are no fields in the &#039;question engine&#039; tables that have files. Except:&lt;br /&gt;
&lt;br /&gt;
* There should be a question_sessions.manualcommentformat column. (But manual comment should not support attached files.)&lt;br /&gt;
&lt;br /&gt;
All the issues are in the &#039;question bank&#039; part, which means the core question bank, and the all the question type plugins.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Core question bank===&lt;br /&gt;
&lt;br /&gt;
* I think that question_categories.info (which is HTML) should not have files. However, we need a question_categories.infoformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas for question.questiontext and question.generalfeedback. We also need to add the missing question.generalfeedbackformat field.&lt;br /&gt;
&lt;br /&gt;
* We need file areas, and ...format columns for question_answers.answer and question_answers.feedback. (Depending on the question type, question_answers.answer may be HTML, or it may not, but where it is not, we will force the ...format value to something appropriate. Anyway, as an example, answers are HTML for multichoice and truefalse, but not for numerical or shortanswer.)&lt;br /&gt;
&lt;br /&gt;
* We must get rid of the question.image column. We need an upgrade to:&lt;br /&gt;
*# Do a database upgrade that appends an img tag to the questiontext, if the img column is not empty;&lt;br /&gt;
*# and copy the file into the right file area;&lt;br /&gt;
*# then drop the question.image column;&lt;br /&gt;
*# remove that field from all editing forms;&lt;br /&gt;
*# remove the places where the image is displayed.&lt;br /&gt;
&lt;br /&gt;
Note that all the above changes require changes to the question editing form for all question types, but hopefully that can mostly be done in the form base class.&lt;br /&gt;
&lt;br /&gt;
* Question import needs to use the file-picker.&lt;br /&gt;
&lt;br /&gt;
* Question export should be changed to put the files in an appropriate file area. I am not sure what the best file area is right now. MDL-15573&lt;br /&gt;
&lt;br /&gt;
===Question types===&lt;br /&gt;
&lt;br /&gt;
====Question types where nothing needs to be done====&lt;br /&gt;
&lt;br /&gt;
These only use the core question tables, or do not need files associated with their own tables.&lt;br /&gt;
&lt;br /&gt;
* Description&lt;br /&gt;
* Essay&lt;br /&gt;
* Missing type&lt;br /&gt;
* Numerical&lt;br /&gt;
* Random&lt;br /&gt;
* Random short-answer matching&lt;br /&gt;
* Short answer&lt;br /&gt;
* True-false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Match====&lt;br /&gt;
&lt;br /&gt;
* question_match_sub.questiontext needs a ...format column and a file area. (answertext does not. It is displayed in a select menu.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Multiple choice====&lt;br /&gt;
&lt;br /&gt;
* correctfeedback, partiallycorrectfeedback and incorrectfeedback all need ...format columns and a file area.&lt;br /&gt;
&lt;br /&gt;
* The choice entry boxes on the editing form should be changed to HTML editors.&lt;br /&gt;
&lt;br /&gt;
====Question types I am not really sure about====&lt;br /&gt;
&lt;br /&gt;
* Calculated* - I don&#039;t really know what Pierre is doing here. I need to get my head round it.&lt;br /&gt;
&lt;br /&gt;
So here is the status of calculated in 2,0.&lt;br /&gt;
&lt;br /&gt;
The calculatedsimple is just a regular calculated that can be edited in a one page because it is not using the shared category datasets. In both on them there is no new field with image to store other than question text and answer feedback.&lt;br /&gt;
&lt;br /&gt;
The answer field is just math formula i.e. plain text.&lt;br /&gt;
&lt;br /&gt;
The multichoice calculated is a multichoice where calculated math formula can be inserted {=...} so the requirements are the same as regular multichoice.&lt;br /&gt;
&lt;br /&gt;
Regular calculated and multichoice calculated used the new table question_calculated_options although regular calculated only used the synchronize field, multichoice calculated using the other fields.&lt;br /&gt;
I prefer to use only one new table and the fields for multichoice are a copy of most of the multichoice ones.&lt;br /&gt;
&lt;br /&gt;
This is a new table in 2,0 so no file conversion.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Multi-answer - probably does not need any other file areas, but the code may need fixing a bit.&lt;br /&gt;
&lt;br /&gt;
So here is the status of Multi-answer in 2,0.&lt;br /&gt;
&lt;br /&gt;
Multi-answer code is the same has in 1.9, the improvements has been on the data validation in the edit_form with additional warnings when the user modify the number or question type in the question text peculiarly when the question has attempts stored.&lt;br /&gt;
 &lt;br /&gt;
I am working on the lang strings.&lt;br /&gt;
 &lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 08:01, 23 May 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==For the future==&lt;br /&gt;
&lt;br /&gt;
As in, Moodle 2.1 or later.&lt;br /&gt;
&lt;br /&gt;
* Support files in student responses and manual comments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-16094&lt;br /&gt;
* Feel free to discuss this with Tim Hunt.&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Numerical_question_type&amp;diff=72353</id>
		<title>Numerical question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Numerical_question_type&amp;diff=72353"/>
		<updated>2010-05-21T17:36:30Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&lt;br /&gt;
From the student perspective, a numerical question looks just like a short-answer question. The difference is that numerical answers are allowed to have an accepted error. This allows a fixed range of answers to be evaluated as one answer. &lt;br /&gt;
&lt;br /&gt;
For example, if the answer is 30 with an accepted error of 5, then any number between 25 and 35 will be accepted as correct.&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
In Moodle 2,0 you will be able to&lt;br /&gt;
&lt;br /&gt;
* grade independently the number and the unit,&lt;br /&gt;
* choose to handle the unit response either as &lt;br /&gt;
** a text input element or as&lt;br /&gt;
** a multichoice radio element,&lt;br /&gt;
* just grade the number with the option to write the unit close to the input element,&lt;br /&gt;
* put the unit either &lt;br /&gt;
** at right of the number as the most common occurence&lt;br /&gt;
** or at left as in $ 100,00.&lt;br /&gt;
&lt;br /&gt;
Furthermore your valid number formats and specific intructions on how to answer will be put near the answer input element.&lt;br /&gt;
An example&lt;br /&gt;
&lt;br /&gt;
[[Image:numerical_multichoice_unit_example_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
{{Moodle 1.7}}&lt;br /&gt;
From Moodle 1.7 onwards, questions may have different answers with different levels of accuracy. That lets you create questions like &amp;quot;What is a root of x^2 - 3x + 2?&amp;quot; and award different levels of credit depending on the accuracy of the answer.&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7 text answers are no longer allowed - [[Short-Answer question type]] should be used instead.&lt;br /&gt;
&lt;br /&gt;
==Numerical question set-up==&lt;br /&gt;
#In Quiz or Question bank&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter a question in the &#039;question text&#039; field. This can include an equation - Moodle has a couple of text filters that allow you to type an equation and have it properly typeset when displayed. The Algebra filter is very good for writing common mathematical expressions in a simple way. More complicated expressions may be written using the [[TeX filter]]. [[Filters]] contains information for administrators on how to enable these filters. Alternatively, select an image to display if you want to add a picture to the question.&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Numerical_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#Add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Now enter the first accepted answer(s). Note: Floating point numbers, e.g. 23.4, may also be written as 23,4 or 2.34E+1.&lt;br /&gt;
#Enter an accepted error for this answer. This is the range above or below the answer that Moodle will accept as a match. For example, if the correct answer is 5, but you will accept 4 or 6 as answers, your accepted error is 1.&lt;br /&gt;
#Enter a grade for this answer.&lt;br /&gt;
#Enter feedback for the accepted answer. This is the text that the student will see if they enter a number within the accepted error of the answer.&lt;br /&gt;
#Repeat for each of the answers you want to accept.  You can provide feedback for &#039;&#039;all&#039;&#039; wrong answers by using a wildcard, i.e. the asterisk character (*), as an answer with grade &#039;None&#039;.&lt;br /&gt;
#Units can also be specified. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. You can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
#Click &#039;Save changes&#039; to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
==Tips and tricks==&lt;br /&gt;
*Remember that numerical questions in the Quiz module are slightly different than those in the Lesson module.&lt;br /&gt;
&lt;br /&gt;
==Error messages==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;One of the answers you entered was not a valid number.&amp;quot; The decimal point used must be a . not a , which is used in some countries. But the error can come anyhow. See (or add to): [http://moodle.org/mod/forum/discuss.php?d=79942 discussion] Though that didn&#039;t help me at the time.&lt;br /&gt;
&lt;br /&gt;
==Numerical questions in pre 1.7 Moodle==&lt;br /&gt;
Numerical questions, in Moodle 1.6 and earlier, can also have case-insensitive non-numerical answers. This is useful whenever the answer for a numerical question is something like N/A, +inf, -inf, NaN etc.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Cloze | embedded / CLOZE]] question type which functions similarly to this one.&lt;br /&gt;
&lt;br /&gt;
*[[Lesson questiontypes]] for more information about a numerical question in a Lesson Activity.&lt;br /&gt;
&lt;br /&gt;
[[fr:Question à réponse numérique]]&lt;br /&gt;
[[ja:数値問題タイプ]]&lt;br /&gt;
[[ca:Tipus_de_pregunta_Numèrica]]&lt;br /&gt;
[[de:Numerische Fragen]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Numerical_question_type&amp;diff=72352</id>
		<title>Numerical question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Numerical_question_type&amp;diff=72352"/>
		<updated>2010-05-21T17:35:01Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&lt;br /&gt;
From the student perspective, a numerical question looks just like a short-answer question. The difference is that numerical answers are allowed to have an accepted error. This allows a fixed range of answers to be evaluated as one answer. &lt;br /&gt;
&lt;br /&gt;
For example, if the answer is 30 with an accepted error of 5, then any number between 25 and 35 will be accepted as correct.&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
In Moodle 2,0 you will be able to&lt;br /&gt;
&lt;br /&gt;
* grade independently the number and the unit,&lt;br /&gt;
* choose to handle the unit response either as &lt;br /&gt;
** a text input element or as&lt;br /&gt;
** a multichoice radio element,&lt;br /&gt;
* just grade the number with the option to write the unit close to the input element,&lt;br /&gt;
* put the unit either &lt;br /&gt;
** at right of the number as the most common occurence&lt;br /&gt;
** or at left as in $ 100,00.&lt;br /&gt;
&lt;br /&gt;
Furthermore your valid number formats and specific intructions on how to answer will be put near the answer input element.&lt;br /&gt;
{{numerical_multichoice_unit_example_1.jpg}}&lt;br /&gt;
 &lt;br /&gt;
{{Moodle 1.7}}&lt;br /&gt;
From Moodle 1.7 onwards, questions may have different answers with different levels of accuracy. That lets you create questions like &amp;quot;What is a root of x^2 - 3x + 2?&amp;quot; and award different levels of credit depending on the accuracy of the answer.&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7 text answers are no longer allowed - [[Short-Answer question type]] should be used instead.&lt;br /&gt;
&lt;br /&gt;
==Numerical question set-up==&lt;br /&gt;
#In Quiz or Question bank&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter a question in the &#039;question text&#039; field. This can include an equation - Moodle has a couple of text filters that allow you to type an equation and have it properly typeset when displayed. The Algebra filter is very good for writing common mathematical expressions in a simple way. More complicated expressions may be written using the [[TeX filter]]. [[Filters]] contains information for administrators on how to enable these filters. Alternatively, select an image to display if you want to add a picture to the question.&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Numerical_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#Add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Now enter the first accepted answer(s). Note: Floating point numbers, e.g. 23.4, may also be written as 23,4 or 2.34E+1.&lt;br /&gt;
#Enter an accepted error for this answer. This is the range above or below the answer that Moodle will accept as a match. For example, if the correct answer is 5, but you will accept 4 or 6 as answers, your accepted error is 1.&lt;br /&gt;
#Enter a grade for this answer.&lt;br /&gt;
#Enter feedback for the accepted answer. This is the text that the student will see if they enter a number within the accepted error of the answer.&lt;br /&gt;
#Repeat for each of the answers you want to accept.  You can provide feedback for &#039;&#039;all&#039;&#039; wrong answers by using a wildcard, i.e. the asterisk character (*), as an answer with grade &#039;None&#039;.&lt;br /&gt;
#Units can also be specified. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. You can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
#Click &#039;Save changes&#039; to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
==Tips and tricks==&lt;br /&gt;
*Remember that numerical questions in the Quiz module are slightly different than those in the Lesson module.&lt;br /&gt;
&lt;br /&gt;
==Error messages==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;One of the answers you entered was not a valid number.&amp;quot; The decimal point used must be a . not a , which is used in some countries. But the error can come anyhow. See (or add to): [http://moodle.org/mod/forum/discuss.php?d=79942 discussion] Though that didn&#039;t help me at the time.&lt;br /&gt;
&lt;br /&gt;
==Numerical questions in pre 1.7 Moodle==&lt;br /&gt;
Numerical questions, in Moodle 1.6 and earlier, can also have case-insensitive non-numerical answers. This is useful whenever the answer for a numerical question is something like N/A, +inf, -inf, NaN etc.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Cloze | embedded / CLOZE]] question type which functions similarly to this one.&lt;br /&gt;
&lt;br /&gt;
*[[Lesson questiontypes]] for more information about a numerical question in a Lesson Activity.&lt;br /&gt;
&lt;br /&gt;
[[fr:Question à réponse numérique]]&lt;br /&gt;
[[ja:数値問題タイプ]]&lt;br /&gt;
[[ca:Tipus_de_pregunta_Numèrica]]&lt;br /&gt;
[[de:Numerische Fragen]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Numerical_question_type&amp;diff=72351</id>
		<title>Numerical question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Numerical_question_type&amp;diff=72351"/>
		<updated>2010-05-21T17:33:10Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
&lt;br /&gt;
From the student perspective, a numerical question looks just like a short-answer question. The difference is that numerical answers are allowed to have an accepted error. This allows a fixed range of answers to be evaluated as one answer. &lt;br /&gt;
&lt;br /&gt;
For example, if the answer is 30 with an accepted error of 5, then any number between 25 and 35 will be accepted as correct.&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
In Moodle 2,0 you will be able to&lt;br /&gt;
&lt;br /&gt;
* grade independently the number and the unit,&lt;br /&gt;
* choose to handle the unit response either as &lt;br /&gt;
** a text input element or as&lt;br /&gt;
** a multichoice radio element,&lt;br /&gt;
* just grade the number with the option to write the unit close to the input element,&lt;br /&gt;
* put the unit either &lt;br /&gt;
** at right of the number as the most common occurence&lt;br /&gt;
** or at left as in $ 100,00.&lt;br /&gt;
&lt;br /&gt;
Furthermore your valid number formats and specific intructions on how to answer will be put near the answer input element.&lt;br /&gt;
{{numerical_.jpg}}&lt;br /&gt;
 &lt;br /&gt;
{{Moodle 1.7}}&lt;br /&gt;
From Moodle 1.7 onwards, questions may have different answers with different levels of accuracy. That lets you create questions like &amp;quot;What is a root of x^2 - 3x + 2?&amp;quot; and award different levels of credit depending on the accuracy of the answer.&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7 text answers are no longer allowed - [[Short-Answer question type]] should be used instead.&lt;br /&gt;
&lt;br /&gt;
==Numerical question set-up==&lt;br /&gt;
#In Quiz or Question bank&lt;br /&gt;
#Select the question category&lt;br /&gt;
#Give the question a descriptive name - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter a question in the &#039;question text&#039; field. This can include an equation - Moodle has a couple of text filters that allow you to type an equation and have it properly typeset when displayed. The Algebra filter is very good for writing common mathematical expressions in a simple way. More complicated expressions may be written using the [[TeX filter]]. [[Filters]] contains information for administrators on how to enable these filters. Alternatively, select an image to display if you want to add a picture to the question.&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices.&lt;br /&gt;
#Set the &#039;default question grade&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;Penalty factor&#039; (see [[Numerical_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#Add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Now enter the first accepted answer(s). Note: Floating point numbers, e.g. 23.4, may also be written as 23,4 or 2.34E+1.&lt;br /&gt;
#Enter an accepted error for this answer. This is the range above or below the answer that Moodle will accept as a match. For example, if the correct answer is 5, but you will accept 4 or 6 as answers, your accepted error is 1.&lt;br /&gt;
#Enter a grade for this answer.&lt;br /&gt;
#Enter feedback for the accepted answer. This is the text that the student will see if they enter a number within the accepted error of the answer.&lt;br /&gt;
#Repeat for each of the answers you want to accept.  You can provide feedback for &#039;&#039;all&#039;&#039; wrong answers by using a wildcard, i.e. the asterisk character (*), as an answer with grade &#039;None&#039;.&lt;br /&gt;
#Units can also be specified. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. You can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
#Click &#039;Save changes&#039; to add the question to the category.&lt;br /&gt;
&lt;br /&gt;
=== Penalty factor ===&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
==Tips and tricks==&lt;br /&gt;
*Remember that numerical questions in the Quiz module are slightly different than those in the Lesson module.&lt;br /&gt;
&lt;br /&gt;
==Error messages==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;One of the answers you entered was not a valid number.&amp;quot; The decimal point used must be a . not a , which is used in some countries. But the error can come anyhow. See (or add to): [http://moodle.org/mod/forum/discuss.php?d=79942 discussion] Though that didn&#039;t help me at the time.&lt;br /&gt;
&lt;br /&gt;
==Numerical questions in pre 1.7 Moodle==&lt;br /&gt;
Numerical questions, in Moodle 1.6 and earlier, can also have case-insensitive non-numerical answers. This is useful whenever the answer for a numerical question is something like N/A, +inf, -inf, NaN etc.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Cloze | embedded / CLOZE]] question type which functions similarly to this one.&lt;br /&gt;
&lt;br /&gt;
*[[Lesson questiontypes]] for more information about a numerical question in a Lesson Activity.&lt;br /&gt;
&lt;br /&gt;
[[fr:Question à réponse numérique]]&lt;br /&gt;
[[ja:数値問題タイプ]]&lt;br /&gt;
[[ca:Tipus_de_pregunta_Numèrica]]&lt;br /&gt;
[[de:Numerische Fragen]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=File:numerical_multichoice_unit_example_1.jpg&amp;diff=72350</id>
		<title>File:numerical multichoice unit example 1.jpg</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=File:numerical_multichoice_unit_example_1.jpg&amp;diff=72350"/>
		<updated>2010-05-21T17:21:51Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: example of a numerical question with the unit set a multichoice&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;example of a numerical question with the unit set a multichoice&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Simple_calculated_question_type&amp;diff=71950</id>
		<title>Simple calculated question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Simple_calculated_question_type&amp;diff=71950"/>
		<updated>2010-05-10T02:02:37Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
Simple calculated questions offer a way to create individual numerical questions whose response is the result of a numerical formula which contain variable numerical values  by the use of wildcards  (i.e &#039;&#039;&#039;{x}&#039;&#039;&#039; , &#039;&#039;&#039;{y}&#039;&#039;&#039;) that are substituted with random values when the quiz is taken.&lt;br /&gt;
&lt;br /&gt;
The simple calculated questions offers the most used features of the calculated question with a much simpler creation interface.&lt;br /&gt;
&lt;br /&gt;
== My first Simple calculated question ==&lt;br /&gt;
As a first example you will create a question asking for the surface of a rectangle. Here are the quick steps we will go over in detail:&lt;br /&gt;
*Create the question content with variables shown in {}&lt;br /&gt;
*Enter the formula using the variables and set the tolerance&lt;br /&gt;
*Determine the range of the generated set of variables that will appear in the question content&lt;br /&gt;
*Review the generated set of question contents&lt;br /&gt;
*Since it is your first, check your work from a student&#039;s view&lt;br /&gt;
&lt;br /&gt;
===Initiating the creation process===&lt;br /&gt;
&lt;br /&gt;
Go to the [[Question bank]], select &amp;quot;create a new question&amp;quot; and in the pop-up window select the Simple calculated.&lt;br /&gt;
The Simple calculated question interface will appear.&lt;br /&gt;
Give a name to your question in the title.&lt;br /&gt;
&lt;br /&gt;
===The question text===&lt;br /&gt;
Fill the question text (note that the &#039;&#039;&#039;{param}&#039;&#039;&#039; names can be chosen at will.&lt;br /&gt;
[[Image:Simple_calculated_first_question_text.jpg]]&lt;br /&gt;
&lt;br /&gt;
===The Correct Answer Formula===&lt;br /&gt;
Fill the Correct Answer Formula using the &#039;&#039;&#039;{param}&#039;&#039;&#039; names used in the question text.&lt;br /&gt;
[[Image:Simple_calculated_first_question_formula.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Other answer and response parameters===&lt;br /&gt;
You will set the Grade to 100%, as this is the only answer in this question.&lt;br /&gt;
&lt;br /&gt;
Leave the other parameters as they appears ( 0.01 relative means ±1% tolerance).&lt;br /&gt;
&lt;br /&gt;
===Find the &#039;&#039;&#039;{param}&#039;&#039;&#039; in the formula===&lt;br /&gt;
In simple calculated only the &#039;&#039;&#039;{param}&#039;&#039;&#039; that are in the formula will be used.&lt;br /&gt;
&lt;br /&gt;
In the question text , the &#039;&#039;&#039;{param}&#039;&#039;&#039; that are in the formula&lt;br /&gt;
 &lt;br /&gt;
will appear with there numerical values i.e 6.7 .&lt;br /&gt;
&lt;br /&gt;
Any other {enclosed text} will appear as is i.e. {enclosed text}.&lt;br /&gt;
&lt;br /&gt;
[[Image:Simple_calculated_first_question_find_wild_card.jpg]]&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;&#039;Click on the button&#039;&#039;&#039;===&lt;br /&gt;
&lt;br /&gt;
On reload the two {b} and {h} will be displayed.&lt;br /&gt;
&lt;br /&gt;
===Set the minimum and maximum values===&lt;br /&gt;
Here the &#039;&#039;&#039;{b}&#039;&#039;&#039; range has been set to a 15-20 range and&lt;br /&gt;
&lt;br /&gt;
the &#039;&#039;&#039;{h}&#039;&#039;&#039; range has been set to a 5-10 range &lt;br /&gt;
&lt;br /&gt;
as we want a rectangle with a larger base than height.&lt;br /&gt;
 &lt;br /&gt;
[[Image:Simple_calculated_first_question_set_min_max.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Select the number of sets to generate (here 10) and to display(here 2)===&lt;br /&gt;
Just to illustrate that you can control the number of values displayed which is useful if you create 100 sets.&lt;br /&gt;
&lt;br /&gt;
Also note the (red) warning that a valid question needs at least one set of {wild card} values.&lt;br /&gt;
You will not be allowed to save the question if you don&#039;t do the next step.&lt;br /&gt;
&lt;br /&gt;
===Click on the generate button ===&lt;br /&gt;
[[Image:Simple_calculated_values.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note the sets are shown in reverse order so the the number indicates how many sets were created.&lt;br /&gt;
&lt;br /&gt;
The two sets illustrate that the variability defined by the Min and Max values.&lt;br /&gt;
&lt;br /&gt;
Note that the formula result is analyzed and &lt;br /&gt;
&lt;br /&gt;
the tolerance limit (here 1% relative) is shown&lt;br /&gt;
&lt;br /&gt;
The correct response that will be shown to the student is also shown. &lt;br /&gt;
&lt;br /&gt;
The 2 decimals where defined are the default values defined as the last parameter under the Correct formula.&lt;br /&gt;
&lt;br /&gt;
===Click on the Save button===&lt;br /&gt;
&lt;br /&gt;
===Test your first Sinple calculated question===&lt;br /&gt;
On the question bank click on the preview icon.&lt;br /&gt;
&lt;br /&gt;
Enter the result you have calculated yourself or click on the Fill with Correct button.&lt;br /&gt;
&lt;br /&gt;
The values should be identical...&lt;br /&gt;
[[Image:Preview_simple_calculated_rectangle_example.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the submit button&lt;br /&gt;
&lt;br /&gt;
[[Image:Previewsimple_calculated_rectangle_example_graded.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Editing a Simple Calculated question: Additional comments==&lt;br /&gt;
&lt;br /&gt;
#Set the &#039;&#039;&#039;default question grade&#039;&#039;&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;&#039;&#039;Penalty factor&#039;&#039;&#039; (see [[Calculated_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
[[Calculated_question_type#Correct_answer_formula|Correct answer formula syntax]] for further details.&lt;br /&gt;
# Choose the &#039;&#039;&#039;grade&#039;&#039;&#039; that the student will get for this question if they give this answer. This should be a percentage of the total marks available. For example, you could give 100% for a correct answer, and 50% for an answer that is nearly right. &#039;&#039;&#039;One of the answers must have a 100% grade&#039;&#039;&#039;.&lt;br /&gt;
#Determine the &#039;&#039;&#039;tolerance&#039;&#039;&#039; for error that you will accept in the answer. The tolerance and tolerance type settings combine to give a range of acceptable scores. So, if tolerance = t, correct answer = x and the difference between the user&#039;s answer and the correct answer is dx, then the tolerance types are as follows:&lt;br /&gt;
##Nominal - mark correct if dx &amp;lt;= t&lt;br /&gt;
##Relative - mark correct if dx / x &amp;lt;= t&lt;br /&gt;
# The next 2 settings, &amp;quot;Correct answer shows&amp;quot; and &amp;quot;Format&amp;quot; determine the &#039;&#039;&#039;precision&#039;&#039;&#039; of the Correct answer shown. They are not used for grading.&lt;br /&gt;
# Add some &#039;&#039;&#039;feedback&#039;&#039;&#039; which the student will see if they enter this answer.&lt;br /&gt;
# You can specify as many answer formulae as you like - click &amp;quot;Add another answer blank&amp;quot; to add more.&lt;br /&gt;
# You can also specify units for the answers. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. If you add more than one unit, you can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
&lt;br /&gt;
==== Penalty factor ====&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
==Correct answer formula syntax ==&lt;br /&gt;
 &lt;br /&gt;
=== DO NOT PUT THE = sign in the formula. ===&lt;br /&gt;
 &lt;br /&gt;
* In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.&lt;br /&gt;
 If more than one correct answer formula input field are displayed when editing, &lt;br /&gt;
 your site has the multiple answer feature. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As a general rule, write these formulas like you would in a calculator e.g. &amp;lt;code&amp;gt;3 + 5 * sin(3/{x})&amp;lt;/code&amp;gt; A notable exception is exponentiation, where x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; cannot be entered as &amp;lt;code&amp;gt;{x}^3&amp;lt;/code&amp;gt;, but instead should be entered as &amp;lt;code&amp;gt;pow(x, 3)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Each function&#039;s placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter &amp;lt;code&amp;gt;sin({a}) + cos({b}*2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* It&#039;s usually better to have too many parentheses (brackets) than too few.  The server won&#039;t care, and the more specific you are about what you mean, the more likely it will like your complex formulas.&lt;br /&gt;
* There is no implicit multiplication.  To you, the human editor, &amp;quot;5(23)&amp;quot; or &amp;quot;5x&amp;quot; may seem perfectly obvious.  To the server doing the math, it&#039;s crazy talk and won&#039;t be understood.  Always use the &amp;quot;*&amp;quot; for multiplication.&lt;br /&gt;
* Any special mathematical function must have parentheses around its values.  Take the sine function in the first bullet point for instance.  Notice that the &#039;&#039;3 / x&#039;&#039; is wrapped in parentheses (brackets)--this is so the server can understand it properly.  Without those parentheses, the server won&#039;t know if you mean &amp;quot;(sin 3) / x&amp;quot; or &amp;quot;sin (3 / x)&amp;quot; and will reject the entire formula accordingly.&lt;br /&gt;
&lt;br /&gt;
==Available functions==&lt;br /&gt;
&lt;br /&gt;
Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;97%&amp;quot; border=&amp;quot;1px&amp;quot;&lt;br /&gt;
!Function&lt;br /&gt;
!Explanation&lt;br /&gt;
|-&lt;br /&gt;
|abs&lt;br /&gt;
|Absolute value&lt;br /&gt;
|-&lt;br /&gt;
|acos&lt;br /&gt;
|Arc cosine -- in radians!!!  Convert your degree measurement to radians before you take the acos of it.&lt;br /&gt;
|-&lt;br /&gt;
|acosh&lt;br /&gt;
|Inverse hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the acosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|asin&lt;br /&gt;
|Arc sine -- in radians!!!  Convert your degree measurement to radians before you take the asin of it.&lt;br /&gt;
|-&lt;br /&gt;
|asinh&lt;br /&gt;
|Inverse hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the asing of it.&lt;br /&gt;
|-&lt;br /&gt;
|atan2&lt;br /&gt;
|Arc tangent of two variables -- pass in two values like (x, y), and you&#039;ll get the atah(y/x), adjusted to the proper quadrant.&lt;br /&gt;
|-&lt;br /&gt;
|atan&lt;br /&gt;
|Arc tangent -- in radians!!!  Convert your degree measurement to radians before you take the atan of it.&lt;br /&gt;
|-&lt;br /&gt;
|atanh&lt;br /&gt;
|Inverse hyperbolic tangent&lt;br /&gt;
|-&lt;br /&gt;
|bindec&lt;br /&gt;
|Binary to decimal&lt;br /&gt;
|-&lt;br /&gt;
|ceil&lt;br /&gt;
|Round fractions up&lt;br /&gt;
|-&lt;br /&gt;
|cos&lt;br /&gt;
|Cosine -- in radians!!!  Convert your degree measurement to radians before you take the cos of it.&lt;br /&gt;
|-&lt;br /&gt;
|cosh&lt;br /&gt;
|Hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the cosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|decbin&lt;br /&gt;
|Decimal to binary&lt;br /&gt;
|-&lt;br /&gt;
|decoct&lt;br /&gt;
|Decimal to octal&lt;br /&gt;
|-&lt;br /&gt;
|deg2rad&lt;br /&gt;
|Converts the number in degrees to the radian equivalent&lt;br /&gt;
|-&lt;br /&gt;
|exp&lt;br /&gt;
|Calculates the exponent of e&lt;br /&gt;
|-&lt;br /&gt;
|expm1&lt;br /&gt;
|Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|floor&lt;br /&gt;
|Round fractions down&lt;br /&gt;
|-&lt;br /&gt;
|fmod&lt;br /&gt;
|Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.&lt;br /&gt;
|-&lt;br /&gt;
|is_finite&lt;br /&gt;
|Finds whether a value is a legal finite number&lt;br /&gt;
|-&lt;br /&gt;
|is_infinite&lt;br /&gt;
|Finds whether a value is infinite&lt;br /&gt;
|-&lt;br /&gt;
|is_nan&lt;br /&gt;
|Finds whether a value is not a number&lt;br /&gt;
|-&lt;br /&gt;
|log10&lt;br /&gt;
|Base-10 logarithm&lt;br /&gt;
|-&lt;br /&gt;
|log1p&lt;br /&gt;
|Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|log&lt;br /&gt;
|Natural logarithm (&#039;&#039;ln&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|Find highest value&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|Find lowest value&lt;br /&gt;
|-&lt;br /&gt;
|octdec&lt;br /&gt;
|Octal to decimal&lt;br /&gt;
|-&lt;br /&gt;
|pi&lt;br /&gt;
|Get value of pi&lt;br /&gt;
|-&lt;br /&gt;
|pow (numberToRaise, NumberRaisedTo)&lt;br /&gt;
|Exponential expression&lt;br /&gt;
|-&lt;br /&gt;
|rad2deg&lt;br /&gt;
|Converts the radian number to the equivalent number in degrees&lt;br /&gt;
|-&lt;br /&gt;
|rand&lt;br /&gt;
|Generate a random integer&lt;br /&gt;
|-&lt;br /&gt;
|round&lt;br /&gt;
|Rounds a float&lt;br /&gt;
|-&lt;br /&gt;
|sin&lt;br /&gt;
|Sine -- in radians!!!  Convert your degree measurement to radians before you take the sin of it.&lt;br /&gt;
|-&lt;br /&gt;
|sinh&lt;br /&gt;
|Hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the sinh of it.&lt;br /&gt;
|-&lt;br /&gt;
|sqrt&lt;br /&gt;
|Square root&lt;br /&gt;
|-&lt;br /&gt;
|tan&lt;br /&gt;
|Tangent -- in radians!!!  Convert your degree measurement to radians before you take the tan of it.&lt;br /&gt;
|-&lt;br /&gt;
|tanh&lt;br /&gt;
|Hyperbolic tangent -- in radians!!!  Convert your degree measurement to radians before you take the tanh of it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Predefined constants==&lt;br /&gt;
Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.&lt;br /&gt;
&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
&lt;br /&gt;
[[de:Berechnungsfragen]]&lt;br /&gt;
[[zh:計算題]]&lt;br /&gt;
&lt;br /&gt;
[[User:Pierre Pichet|Pierre Pichet]] 00:00, 5 June 2009 (UTC)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=71949</id>
		<title>Calculated multichoice question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=71949"/>
		<updated>2010-05-10T02:01:46Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
Calculated multichoice questions are like multichoice questions with the additonal property that the elements to select can include formula results from numeric values that are selected randomly from a set when the quiz is taken.&lt;br /&gt;
They use the same wildcards than Calculated questions and their wildcards can be shared with other Calculated multichoice or regular Calculated questions.&lt;br /&gt;
&lt;br /&gt;
more to follow [[User:Pierre Pichet|Pierre Pichet]] 23:52, 9 May 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Template:Questions&amp;diff=71948</id>
		<title>Template:Questions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Template:Questions&amp;diff=71948"/>
		<updated>2010-05-10T00:02:32Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;sideblock right&amp;quot; style=&amp;quot;width: 12em;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;header&amp;quot;&amp;gt;[[Question bank|Questions]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Question types&#039;&#039;&#039;&lt;br /&gt;
*[[Calculated question type|Calculated]]&lt;br /&gt;
*[[Simple calculated question type|Simple Calculated]]&lt;br /&gt;
*[[Calculated multichoice question type|Calculated Multichoice]]&lt;br /&gt;
*[[Description question type|Description]]&lt;br /&gt;
*[[Essay question type|Essay]]&lt;br /&gt;
*[[Matching question type|Matching]]&lt;br /&gt;
*[[Embedded Answers (Cloze) question type|Embedded Answers (Cloze)]]&lt;br /&gt;
*[[Multiple Choice question type|Multiple Choice]]&lt;br /&gt;
*[[Short-Answer question type|Short-Answer]]&lt;br /&gt;
*[[Numerical question type|Numerical]]&lt;br /&gt;
*[[Random Short-Answer Matching question type|Random Short-Answer Matching]]&lt;br /&gt;
*[[True/False question type|True/False]]&lt;br /&gt;
&#039;&#039;&#039;The question bank&#039;&#039;&#039;&lt;br /&gt;
*[[Question categories]]&lt;br /&gt;
*[[Question permissions]]&lt;br /&gt;
*[[Question contexts]]&lt;br /&gt;
*[[Import questions]]&lt;br /&gt;
*[[Export questions]]&lt;br /&gt;
*[[Questions linking to files]]&lt;br /&gt;
*[[Quiz module]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;[[Category:Questions]]&amp;lt;/includeonly&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;This template will categorise articles that include it into [[:Category:Questions]].&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[fr:Modèle:Questions]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=71947</id>
		<title>Calculated multichoice question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=71947"/>
		<updated>2010-05-09T23:58:54Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
Calculated multichoice questions are like multichoice questions with the additonal property that the elements to select can include formula results from numeric values that are selected randomly from a set when the quiz is taken.&lt;br /&gt;
They use the same wildcards than Calculated questions and there wildcards can be shared with other Calculated multichoice or regular Calculated questions.&lt;br /&gt;
&lt;br /&gt;
more to follow [[User:Pierre Pichet|Pierre Pichet]] 23:52, 9 May 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=71946</id>
		<title>Calculated multichoice question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_multichoice_question_type&amp;diff=71946"/>
		<updated>2010-05-09T23:52:09Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: New page: Calculated multichoice questions are like multichoice questions with the additonal property that the elements to select can include formula results from numeric values that are selected ra...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Calculated multichoice questions are like multichoice questions with the additonal property that the elements to select can include formula results from numeric values that are selected randomly from a set when the quiz is taken.&lt;br /&gt;
They use the same wildcards than Calculated questions and there wildcards can be shared with other Calculated multichoice or regular Calculated questions.&lt;br /&gt;
&lt;br /&gt;
more to follow [[User:Pierre Pichet|Pierre Pichet]] 23:52, 9 May 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=question/type/calculatedmulti&amp;diff=71945</id>
		<title>question/type/calculatedmulti</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=question/type/calculatedmulti&amp;diff=71945"/>
		<updated>2010-05-09T23:46:25Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: Redirecting to Calculated multichoice question type&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#redirect [[Calculated multichoice question type]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=71624</id>
		<title>Calculated question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=71624"/>
		<updated>2010-05-01T06:13:16Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Page 1. Editing a Calculated question */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
Calculated questions offer a way to create individual numerical questions by the use of wildcards  (i.e &#039;&#039;&#039;{x}&#039;&#039;&#039; , &#039;&#039;&#039;{y}&#039;&#039;&#039;) that are substituted with random values when the quiz is taken.&lt;br /&gt;
 &lt;br /&gt;
For example, if you want to create a large number of &#039;&#039;&#039;&amp;quot;Calculate the area of a rectangle&amp;quot;&#039;&#039;&#039; problems to drill your students, you could create a question with two wildcards (i.e. &#039;&#039;&#039;{base}&#039;&#039;&#039;, &#039;&#039;&#039;{height}&#039;&#039;&#039;) and put in the &amp;quot;&#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039;&amp;quot; input field  &#039;&#039;&#039;{base}&#039;&#039;&#039; * &#039;&#039;&#039;{height}&#039;&#039;&#039; ( * being the multiplication sign ).&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039; {base}*{height}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
When a student takes the test, Moodle will randomly select values for &#039;&#039;&#039;{base}&#039;&#039;&#039; and &#039;&#039;&#039;{height}&#039;&#039;&#039; and grade the response using the result of the &#039;&#039;&#039;Correct Answer Formula&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
The test will very rarely appear the same way twice.&lt;br /&gt;
&lt;br /&gt;
== Is this really the question type for you? ==&lt;br /&gt;
The main purpose of the calculated question is to create multiple versions of a question with different numerical values. This means you must have &#039;&#039;&#039;at least one&#039;&#039;&#039; wildcard in one of the answers.&lt;br /&gt;
 &lt;br /&gt;
If you don&#039;t need a random element, use the [[Numerical question type]] instead.&lt;br /&gt;
&lt;br /&gt;
==Wildcards and datasets==&lt;br /&gt;
&lt;br /&gt;
When Moodle delivers a Calculated question to the student, the wildcards are replaced with randomly-selected values. However, these values are not completely random - rather, they are randomly selected from a pre-defined &#039;&#039;dataset&#039;&#039; of possible values. This allows you some control over the possible values chosen - for example, in order to make sure the numbers are realistic.&lt;br /&gt;
&lt;br /&gt;
These datasets can be &#039;&#039;private&#039;&#039; or &#039;&#039;shared&#039;&#039; - private datasets are used by one wildcard within one calculated question; shared datasets are used by one wildcard within all calculated questions that use it.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
To create (or modify) a calculated question there are three pages to work through. The instructions below take you through the pages, step by step:&lt;br /&gt;
&lt;br /&gt;
===Page 1. Editing a Calculated question ===&lt;br /&gt;
&lt;br /&gt;
#Select the question &#039;&#039;&#039;category&#039;&#039;&#039;&lt;br /&gt;
#Any shared wildcards for this category are listed beneath. If you change category, you&#039;ll need to click the &amp;quot;Update the category&amp;quot; button to refresh this list. There may not be any shared wildcards yet - if not, you can create them later if you wish.&lt;br /&gt;
#Give the question a descriptive &#039;&#039;&#039;name&#039;&#039;&#039; - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the &#039;&#039;&#039;question text&#039;&#039;&#039;. This should be the question you want the student to answer, and it must include all the information they need to calculate an answer. Therefore it must contain at least one wildcard, inside curly braces. For example, if you wanted the student to sum numbers A and B, the question text might read: &amp;quot;What is {A} + {B}?&amp;quot;&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices. If you want more control over how the image appears, include it in the question text above, using the HTML editor.&lt;br /&gt;
#Set the &#039;&#039;&#039;default question grade&#039;&#039;&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;&#039;&#039;Penalty factor&#039;&#039;&#039; (see [[Calculated_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#&#039;&#039;Moodle 1.7+:&#039;&#039; If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Next add the &#039;&#039;&#039;formula for the answer&#039;&#039;&#039;. This formula must contain at least the wildcards that appear in the question text. See [[Calculated_question_type#Correct_answer_formula_syntax|Correct answer formula syntax]] for further details.&lt;br /&gt;
# Choose the &#039;&#039;&#039;grade&#039;&#039;&#039; that the student will get for this question if they give this answer. This should be a percentage of the total marks available. For example, you could give 100% for a correct answer, and 50% for an answer that is nearly right. &#039;&#039;&#039;One of the answers must have a 100% grade&#039;&#039;&#039;.&lt;br /&gt;
#Determine the &#039;&#039;&#039;tolerance&#039;&#039;&#039; for error that you will accept in the answer. The tolerance and tolerance type settings combine to give a range of acceptable scores. So, if tolerance = t, correct answer = x and the difference between the user&#039;s answer and the correct answer is dx, then the tolerance types are as follows:&lt;br /&gt;
##Nominal - mark correct if dx &amp;lt;= t&lt;br /&gt;
##Relative - mark correct if dx / x &amp;lt;= t&lt;br /&gt;
##Geometric - mark correct if dx² / x² &amp;lt;= t²&lt;br /&gt;
# The next 2 settings, &amp;quot;Correct answer shows&amp;quot; and &amp;quot;Format&amp;quot; determine the &#039;&#039;&#039;precision&#039;&#039;&#039; of the answer. Use these to select the number of decimal places or significant figures you want to use.&lt;br /&gt;
# Add some &#039;&#039;&#039;feedback&#039;&#039;&#039; which the student will see if they enter this answer.&lt;br /&gt;
# You can specify as many answer formulae as you like - click &amp;quot;Add another answer blank&amp;quot; to add more.&lt;br /&gt;
# You can also specify units for the answers. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. If you add more than one unit, you can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
# Finally (!) you can click &amp;quot;Next page&amp;quot; to save what you&#039;ve done and move on. If you are editing an existing question, you can click &amp;quot;Next page (new question)&amp;quot; to create a completely new question based on an existing one.&lt;br /&gt;
&lt;br /&gt;
==== Penalty factor ====&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
===Page 2. Choose dataset properties ===&lt;br /&gt;
&lt;br /&gt;
Each wildcard that you specify in the answer formula must have an associated set of possible values - this is its &#039;&#039;dataset&#039;&#039;. Each of the wildcards is listed on this page along with a choice of dataset:&lt;br /&gt;
*&#039;&#039;&#039;private&#039;&#039;&#039; i.e. only used by this question&lt;br /&gt;
*&#039;&#039;&#039;shared&#039;&#039;&#039; i.e shared with other calculated questions in the same category&lt;br /&gt;
&lt;br /&gt;
Using a shared dataset can save time when you are creating a lot of similar calculated questions.&lt;br /&gt;
&lt;br /&gt;
If there is anything in the question text that looks like a wildcard, but does not appear in any of the answer formulae, you can specify whether or not this is meant to be a wildcard. If it is, you can choose whether it should use a private or shared dataset.&lt;br /&gt;
&lt;br /&gt;
To continue, simply choose your preferred dataset for each wildcard, then click &amp;quot;Next Page&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Page 3. Edit the datasets ===&lt;br /&gt;
&lt;br /&gt;
Now we need to create the set of possible values that each wildcard can take. &#039;&#039;Warning&#039;&#039; - this page is a bit confusing!&lt;br /&gt;
&lt;br /&gt;
There are two ways of creating values - you can type them in yourself and add them to the list, or you can have Moodle generate them for you.&lt;br /&gt;
&lt;br /&gt;
==== Adding/deleting your own values ====&lt;br /&gt;
&lt;br /&gt;
Adding individual values to the list is easy:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Param&#039; field for each wildcard, enter the value you want&lt;br /&gt;
# Scroll down to the &#039;Add&#039; section and click the Add button (leaving the number of items set to 1)&lt;br /&gt;
# Repeat the above steps as many times as necessary (the maximum number of items is 100)&lt;br /&gt;
&lt;br /&gt;
To delete values from the list:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Delete&#039; section, select the number of items to delete&lt;br /&gt;
# Click the Delete button&lt;br /&gt;
&lt;br /&gt;
==== Letting Moodle create values ====&lt;br /&gt;
&lt;br /&gt;
# Start with the &amp;quot;Range of Values&amp;quot; fields, and enter the lower and upper limits for the values you would accept&lt;br /&gt;
# Choose a number of decimal places for the value&lt;br /&gt;
# Choose the distribution of values between the limits - &#039;uniform&#039; means any value between the limits is equally likely to be generated; &#039;loguniform&#039; means that values towards the lower limit are more likely.&lt;br /&gt;
# Now move down to the &#039;Add&#039; section and click on &amp;quot;force regeneration&amp;quot;&lt;br /&gt;
# In the menu next to the Add button, choose the number of sets of random values (items) you wish to add to the list. (Note that the maximum total number of items in your list is 100.)&lt;br /&gt;
# Finally, click Add to append the new values to the list&lt;br /&gt;
# &#039;&#039;&#039;Note:&#039;&#039;&#039; If you want more control over the items that Moodle adds, you can do them one at a time and preview the values before you add them. Click the &amp;quot;Get New Item to Add&amp;quot; button to make Moodle generate new values in the &amp;quot;Item to Add&amp;quot; section at the top. If you like them, click &amp;quot;Add&amp;quot; for 1 item; if not, click &amp;quot;Get New Item to Add&amp;quot; again to get new values.&lt;br /&gt;
&lt;br /&gt;
==== Finishing off ====&lt;br /&gt;
&lt;br /&gt;
Once your list of items (values) is complete, you are finished. It&#039;s up to you how many values you add - the more values you add, the more a question can be used by the students without them seeing the same values repeatedly.&lt;br /&gt;
&lt;br /&gt;
Note that if you delete values from the list, you can put them back again. Change the &amp;quot;Next Item to Add&amp;quot; option to &amp;quot;reuse previous value if available&amp;quot;, then the next time you add items, Moodle will restore your previously-deleted items from the dataset. &lt;br /&gt;
&lt;br /&gt;
Once your list of values is complete, you can click &#039;Save changes&#039; to finish.&lt;br /&gt;
&lt;br /&gt;
==== What does the &#039;Update the datasets parameters&#039; button do? ====&lt;br /&gt;
&lt;br /&gt;
As far as I can tell, it has the same function as the &amp;quot;Get New Item to Add&amp;quot; button, i.e. it generates a new set of values and displays them in the &amp;quot;Item to Add&amp;quot; section. However, it is less conveniently placed that that button, so it is probably best ignored.&lt;br /&gt;
&lt;br /&gt;
==Correct answer formula syntax==&lt;br /&gt;
 &lt;br /&gt;
=== DO NOT PUT THE = sign in the formula. ===&lt;br /&gt;
 &lt;br /&gt;
* In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.&lt;br /&gt;
 If more than one correct answer formula input field are displayed when editing, &lt;br /&gt;
 your site has the multiple answer feature. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As a general rule, write these formulas like you would in a calculator e.g. &amp;lt;code&amp;gt;3 + 5 * sin(3/{x})&amp;lt;/code&amp;gt; A notable exception is exponentiation, where x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; cannot be entered as &amp;lt;code&amp;gt;{x}^3&amp;lt;/code&amp;gt;, but instead should be entered as &amp;lt;code&amp;gt;pow({x}, 3)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Each function&#039;s placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter &amp;lt;code&amp;gt;sin({a}) + cos({b}*2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* It&#039;s usually better to have too many parentheses (brackets) than too few.  The server won&#039;t care, and the more specific you are about what you mean, the more likely it will like your complex formulas.&lt;br /&gt;
* There is no implicit multiplication.  To you, the human editor, &amp;quot;5(23)&amp;quot; or &amp;quot;5x&amp;quot; may seem perfectly obvious.  To the server doing the math, it&#039;s crazy talk and won&#039;t be understood.  Always use the &amp;quot;*&amp;quot; for multiplication.&lt;br /&gt;
* Any special mathematical function must have parentheses around its values.  Take the sine function in the first bullet point for instance.  Notice that the &#039;&#039;3 / x&#039;&#039; is wrapped in parentheses (brackets)--this is so the server can understand it properly.  Without those parentheses, the server won&#039;t know if you mean &amp;quot;(sin 3) / x&amp;quot; or &amp;quot;sin (3 / x)&amp;quot; and will reject the entire formula accordingly.&lt;br /&gt;
&lt;br /&gt;
==Available functions==&lt;br /&gt;
&lt;br /&gt;
Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;97%&amp;quot; border=&amp;quot;1px&amp;quot;&lt;br /&gt;
!Function&lt;br /&gt;
!Explanation&lt;br /&gt;
|-&lt;br /&gt;
|abs&lt;br /&gt;
|Absolute value&lt;br /&gt;
|-&lt;br /&gt;
|acos&lt;br /&gt;
|Arc cosine -- in radians!!!  Convert your degree measurement to radians before you take the acos of it.&lt;br /&gt;
|-&lt;br /&gt;
|acosh&lt;br /&gt;
|Inverse hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the acosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|asin&lt;br /&gt;
|Arc sine -- in radians!!!  Convert your degree measurement to radians before you take the asin of it.&lt;br /&gt;
|-&lt;br /&gt;
|asinh&lt;br /&gt;
|Inverse hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the asing of it.&lt;br /&gt;
|-&lt;br /&gt;
|atan2&lt;br /&gt;
|Arc tangent of two variables -- pass in two values like (x, y), and you&#039;ll get the atah(y/x), adjusted to the proper quadrant.&lt;br /&gt;
|-&lt;br /&gt;
|atan&lt;br /&gt;
|Arc tangent -- in radians!!!  Convert your degree measurement to radians before you take the atan of it.&lt;br /&gt;
|-&lt;br /&gt;
|atanh&lt;br /&gt;
|Inverse hyperbolic tangent&lt;br /&gt;
|-&lt;br /&gt;
|bindec&lt;br /&gt;
|Binary to decimal&lt;br /&gt;
|-&lt;br /&gt;
|ceil&lt;br /&gt;
|Round fractions up&lt;br /&gt;
|-&lt;br /&gt;
|cos&lt;br /&gt;
|Cosine -- in radians!!!  Convert your degree measurement to radians before you take the cos of it.&lt;br /&gt;
|-&lt;br /&gt;
|cosh&lt;br /&gt;
|Hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the cosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|decbin&lt;br /&gt;
|Decimal to binary&lt;br /&gt;
|-&lt;br /&gt;
|decoct&lt;br /&gt;
|Decimal to octal&lt;br /&gt;
|-&lt;br /&gt;
|deg2rad&lt;br /&gt;
|Converts the number in degrees to the radian equivalent&lt;br /&gt;
|-&lt;br /&gt;
|exp&lt;br /&gt;
|Calculates the exponent of e&lt;br /&gt;
|-&lt;br /&gt;
|expm1&lt;br /&gt;
|Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|floor&lt;br /&gt;
|Round fractions down&lt;br /&gt;
|-&lt;br /&gt;
|fmod&lt;br /&gt;
|Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.&lt;br /&gt;
|-&lt;br /&gt;
|is_finite&lt;br /&gt;
|Finds whether a value is a legal finite number&lt;br /&gt;
|-&lt;br /&gt;
|is_infinite&lt;br /&gt;
|Finds whether a value is infinite&lt;br /&gt;
|-&lt;br /&gt;
|is_nan&lt;br /&gt;
|Finds whether a value is not a number&lt;br /&gt;
|-&lt;br /&gt;
|log10&lt;br /&gt;
|Base-10 logarithm&lt;br /&gt;
|-&lt;br /&gt;
|log1p&lt;br /&gt;
|Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|log&lt;br /&gt;
|Natural logarithm (&#039;&#039;ln&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|Find highest value&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|Find lowest value&lt;br /&gt;
|-&lt;br /&gt;
|octdec&lt;br /&gt;
|Octal to decimal&lt;br /&gt;
|-&lt;br /&gt;
|pi()&lt;br /&gt;
|Get value of pi - the function does not take an argument, like in Excel.&lt;br /&gt;
|-&lt;br /&gt;
|pow (numberToRaise, NumberRaisedTo)&lt;br /&gt;
|Exponential expression&lt;br /&gt;
|-&lt;br /&gt;
|rad2deg&lt;br /&gt;
|Converts the radian number to the equivalent number in degrees&lt;br /&gt;
|-&lt;br /&gt;
|rand&lt;br /&gt;
|Generate a random integer&lt;br /&gt;
|-&lt;br /&gt;
|round&lt;br /&gt;
|Rounds a float&lt;br /&gt;
|-&lt;br /&gt;
|sin&lt;br /&gt;
|Sine -- in radians!!!  Convert your degree measurement to radians before you take the sin of it.&lt;br /&gt;
|-&lt;br /&gt;
|sinh&lt;br /&gt;
|Hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the sinh of it.&lt;br /&gt;
|-&lt;br /&gt;
|sqrt&lt;br /&gt;
|Square root&lt;br /&gt;
|-&lt;br /&gt;
|tan&lt;br /&gt;
|Tangent -- in radians!!!  Convert your degree measurement to radians before you take the tan of it.&lt;br /&gt;
|-&lt;br /&gt;
|tanh&lt;br /&gt;
|Hyperbolic tangent -- in radians!!!  Convert your degree measurement to radians before you take the tanh of it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Predefined constants==&lt;br /&gt;
Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.&lt;br /&gt;
&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
&lt;br /&gt;
[[de:Berechnungsfragen]]&lt;br /&gt;
[[fr:Question calculée]]&lt;br /&gt;
[[zh:計算題]]&lt;br /&gt;
[[ja:計算問題タイプ]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=71623</id>
		<title>Calculated question type</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/33/en/index.php?title=Calculated_question_type&amp;diff=71623"/>
		<updated>2010-05-01T06:10:54Z</updated>

		<summary type="html">&lt;p&gt;Ppichet: /* Correct answer formula syntax */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Questions}}&lt;br /&gt;
Calculated questions offer a way to create individual numerical questions by the use of wildcards  (i.e &#039;&#039;&#039;{x}&#039;&#039;&#039; , &#039;&#039;&#039;{y}&#039;&#039;&#039;) that are substituted with random values when the quiz is taken.&lt;br /&gt;
 &lt;br /&gt;
For example, if you want to create a large number of &#039;&#039;&#039;&amp;quot;Calculate the area of a rectangle&amp;quot;&#039;&#039;&#039; problems to drill your students, you could create a question with two wildcards (i.e. &#039;&#039;&#039;{base}&#039;&#039;&#039;, &#039;&#039;&#039;{height}&#039;&#039;&#039;) and put in the &amp;quot;&#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039;&amp;quot; input field  &#039;&#039;&#039;{base}&#039;&#039;&#039; * &#039;&#039;&#039;{height}&#039;&#039;&#039; ( * being the multiplication sign ).&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Correct Answer Formula=&#039;&#039;&#039; {base}*{height}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
When a student takes the test, Moodle will randomly select values for &#039;&#039;&#039;{base}&#039;&#039;&#039; and &#039;&#039;&#039;{height}&#039;&#039;&#039; and grade the response using the result of the &#039;&#039;&#039;Correct Answer Formula&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
The test will very rarely appear the same way twice.&lt;br /&gt;
&lt;br /&gt;
== Is this really the question type for you? ==&lt;br /&gt;
The main purpose of the calculated question is to create multiple versions of a question with different numerical values. This means you must have &#039;&#039;&#039;at least one&#039;&#039;&#039; wildcard in one of the answers.&lt;br /&gt;
 &lt;br /&gt;
If you don&#039;t need a random element, use the [[Numerical question type]] instead.&lt;br /&gt;
&lt;br /&gt;
==Wildcards and datasets==&lt;br /&gt;
&lt;br /&gt;
When Moodle delivers a Calculated question to the student, the wildcards are replaced with randomly-selected values. However, these values are not completely random - rather, they are randomly selected from a pre-defined &#039;&#039;dataset&#039;&#039; of possible values. This allows you some control over the possible values chosen - for example, in order to make sure the numbers are realistic.&lt;br /&gt;
&lt;br /&gt;
These datasets can be &#039;&#039;private&#039;&#039; or &#039;&#039;shared&#039;&#039; - private datasets are used by one wildcard within one calculated question; shared datasets are used by one wildcard within all calculated questions that use it.&lt;br /&gt;
&lt;br /&gt;
==Question set-up==&lt;br /&gt;
To create (or modify) a calculated question there are three pages to work through. The instructions below take you through the pages, step by step:&lt;br /&gt;
&lt;br /&gt;
===Page 1. Editing a Calculated question ===&lt;br /&gt;
&lt;br /&gt;
#Select the question &#039;&#039;&#039;category&#039;&#039;&#039;&lt;br /&gt;
#Any shared wildcards for this category are listed beneath. If you change category, you&#039;ll need to click the &amp;quot;Update the category&amp;quot; button to refresh this list. There may not be any shared wildcards yet - if not, you can create them later if you wish.&lt;br /&gt;
#Give the question a descriptive &#039;&#039;&#039;name&#039;&#039;&#039; - this allows you to identify it in the question bank.&lt;br /&gt;
#Enter the &#039;&#039;&#039;question text&#039;&#039;&#039;. This should be the question you want the student to answer, and it must include all the information they need to calculate an answer. Therefore it must contain at least one wildcard, inside curly braces. For example, if you wanted the student to sum numbers A and B, the question text might read: &amp;quot;What is {A} + {B}?&amp;quot;&lt;br /&gt;
#Select an image to display if you want to add a picture to the question. For the student, it appears immediately after the question text and before the choices. If you want more control over how the image appears, include it in the question text above, using the HTML editor.&lt;br /&gt;
#Set the &#039;&#039;&#039;default question grade&#039;&#039;&#039; (i.e. the maximum number of marks for this question).&lt;br /&gt;
#Set the &#039;&#039;&#039;Penalty factor&#039;&#039;&#039; (see [[Calculated_question_type#Penalty_factor|Penalty factor]] below).&lt;br /&gt;
#&#039;&#039;Moodle 1.7+:&#039;&#039; If you wish, add general feedback. This is text that appears to the student after he/she has answered the question.&lt;br /&gt;
#Next add the &#039;&#039;&#039;formula for the answer&#039;&#039;&#039;. This formula must contain at least the wildcards that appear in the question text. See [[Calculated_question_type#Correct_answer_formula|Correct answer formula syntax]] for further details.&lt;br /&gt;
# Choose the &#039;&#039;&#039;grade&#039;&#039;&#039; that the student will get for this question if they give this answer. This should be a percentage of the total marks available. For example, you could give 100% for a correct answer, and 50% for an answer that is nearly right. &#039;&#039;&#039;One of the answers must have a 100% grade&#039;&#039;&#039;.&lt;br /&gt;
#Determine the &#039;&#039;&#039;tolerance&#039;&#039;&#039; for error that you will accept in the answer. The tolerance and tolerance type settings combine to give a range of acceptable scores. So, if tolerance = t, correct answer = x and the difference between the user&#039;s answer and the correct answer is dx, then the tolerance types are as follows:&lt;br /&gt;
##Nominal - mark correct if dx &amp;lt;= t&lt;br /&gt;
##Relative - mark correct if dx / x &amp;lt;= t&lt;br /&gt;
##Geometric - mark correct if dx² / x² &amp;lt;= t²&lt;br /&gt;
# The next 2 settings, &amp;quot;Correct answer shows&amp;quot; and &amp;quot;Format&amp;quot; determine the &#039;&#039;&#039;precision&#039;&#039;&#039; of the answer. Use these to select the number of decimal places or significant figures you want to use.&lt;br /&gt;
# Add some &#039;&#039;&#039;feedback&#039;&#039;&#039; which the student will see if they enter this answer.&lt;br /&gt;
# You can specify as many answer formulae as you like - click &amp;quot;Add another answer blank&amp;quot; to add more.&lt;br /&gt;
# You can also specify units for the answers. For example, if you enter a unit of &#039;cm&#039; here, and the accepted answer is 15, then the answers &#039;15cm&#039; and &#039;15&#039; are both accepted as correct. If you add more than one unit, you can also specify a multiplier. So, if your main answer was 5500 with unit W, you can also add the unit kW with a multiplier of 0.001. This means that the answers &#039;5500&#039;, &#039;5500W&#039; or &#039;5.5kW&#039; would all be marked correct. Note that the accepted error is also multiplied, so an allowed error of 100W would become an error of 0.1kW.&lt;br /&gt;
# Finally (!) you can click &amp;quot;Next page&amp;quot; to save what you&#039;ve done and move on. If you are editing an existing question, you can click &amp;quot;Next page (new question)&amp;quot; to create a completely new question based on an existing one.&lt;br /&gt;
&lt;br /&gt;
==== Penalty factor ====&lt;br /&gt;
&lt;br /&gt;
The &#039;penalty factor&#039; 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 &#039;&#039;&#039;maximum&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
===Page 2. Choose dataset properties ===&lt;br /&gt;
&lt;br /&gt;
Each wildcard that you specify in the answer formula must have an associated set of possible values - this is its &#039;&#039;dataset&#039;&#039;. Each of the wildcards is listed on this page along with a choice of dataset:&lt;br /&gt;
*&#039;&#039;&#039;private&#039;&#039;&#039; i.e. only used by this question&lt;br /&gt;
*&#039;&#039;&#039;shared&#039;&#039;&#039; i.e shared with other calculated questions in the same category&lt;br /&gt;
&lt;br /&gt;
Using a shared dataset can save time when you are creating a lot of similar calculated questions.&lt;br /&gt;
&lt;br /&gt;
If there is anything in the question text that looks like a wildcard, but does not appear in any of the answer formulae, you can specify whether or not this is meant to be a wildcard. If it is, you can choose whether it should use a private or shared dataset.&lt;br /&gt;
&lt;br /&gt;
To continue, simply choose your preferred dataset for each wildcard, then click &amp;quot;Next Page&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Page 3. Edit the datasets ===&lt;br /&gt;
&lt;br /&gt;
Now we need to create the set of possible values that each wildcard can take. &#039;&#039;Warning&#039;&#039; - this page is a bit confusing!&lt;br /&gt;
&lt;br /&gt;
There are two ways of creating values - you can type them in yourself and add them to the list, or you can have Moodle generate them for you.&lt;br /&gt;
&lt;br /&gt;
==== Adding/deleting your own values ====&lt;br /&gt;
&lt;br /&gt;
Adding individual values to the list is easy:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Param&#039; field for each wildcard, enter the value you want&lt;br /&gt;
# Scroll down to the &#039;Add&#039; section and click the Add button (leaving the number of items set to 1)&lt;br /&gt;
# Repeat the above steps as many times as necessary (the maximum number of items is 100)&lt;br /&gt;
&lt;br /&gt;
To delete values from the list:&lt;br /&gt;
&lt;br /&gt;
# In the &#039;Delete&#039; section, select the number of items to delete&lt;br /&gt;
# Click the Delete button&lt;br /&gt;
&lt;br /&gt;
==== Letting Moodle create values ====&lt;br /&gt;
&lt;br /&gt;
# Start with the &amp;quot;Range of Values&amp;quot; fields, and enter the lower and upper limits for the values you would accept&lt;br /&gt;
# Choose a number of decimal places for the value&lt;br /&gt;
# Choose the distribution of values between the limits - &#039;uniform&#039; means any value between the limits is equally likely to be generated; &#039;loguniform&#039; means that values towards the lower limit are more likely.&lt;br /&gt;
# Now move down to the &#039;Add&#039; section and click on &amp;quot;force regeneration&amp;quot;&lt;br /&gt;
# In the menu next to the Add button, choose the number of sets of random values (items) you wish to add to the list. (Note that the maximum total number of items in your list is 100.)&lt;br /&gt;
# Finally, click Add to append the new values to the list&lt;br /&gt;
# &#039;&#039;&#039;Note:&#039;&#039;&#039; If you want more control over the items that Moodle adds, you can do them one at a time and preview the values before you add them. Click the &amp;quot;Get New Item to Add&amp;quot; button to make Moodle generate new values in the &amp;quot;Item to Add&amp;quot; section at the top. If you like them, click &amp;quot;Add&amp;quot; for 1 item; if not, click &amp;quot;Get New Item to Add&amp;quot; again to get new values.&lt;br /&gt;
&lt;br /&gt;
==== Finishing off ====&lt;br /&gt;
&lt;br /&gt;
Once your list of items (values) is complete, you are finished. It&#039;s up to you how many values you add - the more values you add, the more a question can be used by the students without them seeing the same values repeatedly.&lt;br /&gt;
&lt;br /&gt;
Note that if you delete values from the list, you can put them back again. Change the &amp;quot;Next Item to Add&amp;quot; option to &amp;quot;reuse previous value if available&amp;quot;, then the next time you add items, Moodle will restore your previously-deleted items from the dataset. &lt;br /&gt;
&lt;br /&gt;
Once your list of values is complete, you can click &#039;Save changes&#039; to finish.&lt;br /&gt;
&lt;br /&gt;
==== What does the &#039;Update the datasets parameters&#039; button do? ====&lt;br /&gt;
&lt;br /&gt;
As far as I can tell, it has the same function as the &amp;quot;Get New Item to Add&amp;quot; button, i.e. it generates a new set of values and displays them in the &amp;quot;Item to Add&amp;quot; section. However, it is less conveniently placed that that button, so it is probably best ignored.&lt;br /&gt;
&lt;br /&gt;
==Correct answer formula syntax==&lt;br /&gt;
 &lt;br /&gt;
=== DO NOT PUT THE = sign in the formula. ===&lt;br /&gt;
 &lt;br /&gt;
* In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.&lt;br /&gt;
 If more than one correct answer formula input field are displayed when editing, &lt;br /&gt;
 your site has the multiple answer feature. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As a general rule, write these formulas like you would in a calculator e.g. &amp;lt;code&amp;gt;3 + 5 * sin(3/{x})&amp;lt;/code&amp;gt; A notable exception is exponentiation, where x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; cannot be entered as &amp;lt;code&amp;gt;{x}^3&amp;lt;/code&amp;gt;, but instead should be entered as &amp;lt;code&amp;gt;pow({x}, 3)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Each function&#039;s placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter &amp;lt;code&amp;gt;sin({a}) + cos({b}*2)&amp;lt;/code&amp;gt;.&lt;br /&gt;
* It&#039;s usually better to have too many parentheses (brackets) than too few.  The server won&#039;t care, and the more specific you are about what you mean, the more likely it will like your complex formulas.&lt;br /&gt;
* There is no implicit multiplication.  To you, the human editor, &amp;quot;5(23)&amp;quot; or &amp;quot;5x&amp;quot; may seem perfectly obvious.  To the server doing the math, it&#039;s crazy talk and won&#039;t be understood.  Always use the &amp;quot;*&amp;quot; for multiplication.&lt;br /&gt;
* Any special mathematical function must have parentheses around its values.  Take the sine function in the first bullet point for instance.  Notice that the &#039;&#039;3 / x&#039;&#039; is wrapped in parentheses (brackets)--this is so the server can understand it properly.  Without those parentheses, the server won&#039;t know if you mean &amp;quot;(sin 3) / x&amp;quot; or &amp;quot;sin (3 / x)&amp;quot; and will reject the entire formula accordingly.&lt;br /&gt;
&lt;br /&gt;
==Available functions==&lt;br /&gt;
&lt;br /&gt;
Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.&lt;br /&gt;
&lt;br /&gt;
{| width=&amp;quot;97%&amp;quot; border=&amp;quot;1px&amp;quot;&lt;br /&gt;
!Function&lt;br /&gt;
!Explanation&lt;br /&gt;
|-&lt;br /&gt;
|abs&lt;br /&gt;
|Absolute value&lt;br /&gt;
|-&lt;br /&gt;
|acos&lt;br /&gt;
|Arc cosine -- in radians!!!  Convert your degree measurement to radians before you take the acos of it.&lt;br /&gt;
|-&lt;br /&gt;
|acosh&lt;br /&gt;
|Inverse hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the acosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|asin&lt;br /&gt;
|Arc sine -- in radians!!!  Convert your degree measurement to radians before you take the asin of it.&lt;br /&gt;
|-&lt;br /&gt;
|asinh&lt;br /&gt;
|Inverse hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the asing of it.&lt;br /&gt;
|-&lt;br /&gt;
|atan2&lt;br /&gt;
|Arc tangent of two variables -- pass in two values like (x, y), and you&#039;ll get the atah(y/x), adjusted to the proper quadrant.&lt;br /&gt;
|-&lt;br /&gt;
|atan&lt;br /&gt;
|Arc tangent -- in radians!!!  Convert your degree measurement to radians before you take the atan of it.&lt;br /&gt;
|-&lt;br /&gt;
|atanh&lt;br /&gt;
|Inverse hyperbolic tangent&lt;br /&gt;
|-&lt;br /&gt;
|bindec&lt;br /&gt;
|Binary to decimal&lt;br /&gt;
|-&lt;br /&gt;
|ceil&lt;br /&gt;
|Round fractions up&lt;br /&gt;
|-&lt;br /&gt;
|cos&lt;br /&gt;
|Cosine -- in radians!!!  Convert your degree measurement to radians before you take the cos of it.&lt;br /&gt;
|-&lt;br /&gt;
|cosh&lt;br /&gt;
|Hyperbolic cosine -- in radians!!!  Convert your degree measurement to radians before you take the cosh of it.&lt;br /&gt;
|-&lt;br /&gt;
|decbin&lt;br /&gt;
|Decimal to binary&lt;br /&gt;
|-&lt;br /&gt;
|decoct&lt;br /&gt;
|Decimal to octal&lt;br /&gt;
|-&lt;br /&gt;
|deg2rad&lt;br /&gt;
|Converts the number in degrees to the radian equivalent&lt;br /&gt;
|-&lt;br /&gt;
|exp&lt;br /&gt;
|Calculates the exponent of e&lt;br /&gt;
|-&lt;br /&gt;
|expm1&lt;br /&gt;
|Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|floor&lt;br /&gt;
|Round fractions down&lt;br /&gt;
|-&lt;br /&gt;
|fmod&lt;br /&gt;
|Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.&lt;br /&gt;
|-&lt;br /&gt;
|is_finite&lt;br /&gt;
|Finds whether a value is a legal finite number&lt;br /&gt;
|-&lt;br /&gt;
|is_infinite&lt;br /&gt;
|Finds whether a value is infinite&lt;br /&gt;
|-&lt;br /&gt;
|is_nan&lt;br /&gt;
|Finds whether a value is not a number&lt;br /&gt;
|-&lt;br /&gt;
|log10&lt;br /&gt;
|Base-10 logarithm&lt;br /&gt;
|-&lt;br /&gt;
|log1p&lt;br /&gt;
|Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero&lt;br /&gt;
|-&lt;br /&gt;
|log&lt;br /&gt;
|Natural logarithm (&#039;&#039;ln&#039;&#039;)&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|Find highest value&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|Find lowest value&lt;br /&gt;
|-&lt;br /&gt;
|octdec&lt;br /&gt;
|Octal to decimal&lt;br /&gt;
|-&lt;br /&gt;
|pi()&lt;br /&gt;
|Get value of pi - the function does not take an argument, like in Excel.&lt;br /&gt;
|-&lt;br /&gt;
|pow (numberToRaise, NumberRaisedTo)&lt;br /&gt;
|Exponential expression&lt;br /&gt;
|-&lt;br /&gt;
|rad2deg&lt;br /&gt;
|Converts the radian number to the equivalent number in degrees&lt;br /&gt;
|-&lt;br /&gt;
|rand&lt;br /&gt;
|Generate a random integer&lt;br /&gt;
|-&lt;br /&gt;
|round&lt;br /&gt;
|Rounds a float&lt;br /&gt;
|-&lt;br /&gt;
|sin&lt;br /&gt;
|Sine -- in radians!!!  Convert your degree measurement to radians before you take the sin of it.&lt;br /&gt;
|-&lt;br /&gt;
|sinh&lt;br /&gt;
|Hyperbolic sine -- in radians!!!  Convert your degree measurement to radians before you take the sinh of it.&lt;br /&gt;
|-&lt;br /&gt;
|sqrt&lt;br /&gt;
|Square root&lt;br /&gt;
|-&lt;br /&gt;
|tan&lt;br /&gt;
|Tangent -- in radians!!!  Convert your degree measurement to radians before you take the tan of it.&lt;br /&gt;
|-&lt;br /&gt;
|tanh&lt;br /&gt;
|Hyperbolic tangent -- in radians!!!  Convert your degree measurement to radians before you take the tanh of it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Predefined constants==&lt;br /&gt;
Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.&lt;br /&gt;
&lt;br /&gt;
[[Category:Questions]]&lt;br /&gt;
[[Category:Mathematics]]&lt;br /&gt;
&lt;br /&gt;
[[de:Berechnungsfragen]]&lt;br /&gt;
[[fr:Question calculée]]&lt;br /&gt;
[[zh:計算題]]&lt;br /&gt;
[[ja:計算問題タイプ]]&lt;/div&gt;</summary>
		<author><name>Ppichet</name></author>
	</entry>
</feed>