Formula qtype : convert to float

Formula qtype : convert to float

by Jean-Nicolas Gautier -
Number of replies: 2

Moodle 3.8

I'd like to produce questions for chemistry using formula qtype.

I use a set in which each element is a molecule describe by its name, its molecular formula, its mass and its solubility.

It looks like :

molecule_set = {["KBr", "bromure de potassium", 119.0, 65.3], ["Cu(NO{_3})_{2}", "nitrate de cuivre(II)", 188.0, 125.0] }; #200 elements at all

Masse and solubility should be interpreted as float but they are interpreted as string since name and formula are strings.

My question is "how to convert string to float in formula qtype"?

Is there an other way to build my question to avoid this problem?

Thanks



Average of ratings: -
In reply to Jean-Nicolas Gautier

Re: Formula qtype : convert to float

by Matthias Giger -
Picture of Particularly helpful Moodlers
Use different arrays. Something like this:

Arrays with different types
It is best to create them from a spreadsheet so that you don't make a mistake with the indexes.
Average of ratings: Useful (2)
In reply to Matthias Giger

Re: Formula qtype : convert to float

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Matthias' solution is excellent. However, in his example, you should set random = {0:4:1} because the end value is, by definition, not included in the set.

Another equivalent way to present the example of Matthias is as follows:

ForumQuiz_20200330_1758.png?time=1585606141167

Average of ratings: Useful (1)