<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="stack">
    <name>
      <text>Chemistry sample question: Molar mass of elements</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[<p>
\(\require{mhchem}\)
Calculate the molar mass of the following substance: \(\ce{@CN@}\).</p>
<p>[[input:ans1]] [[validation:ans1]]</p>]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text><![CDATA[<p>\(\require{mhchem}\)
In general, the calculation is
\[ 𝑀 = \sum_{j} 𝑁_j\, M_j\]
where \(𝑁_j\) is the number of atoms of element \(j\) and \(M_j\) is the mass of elememnt \(j\).
</p>
<p>In this question we calculate the molar mass of \(\ce{@CN@}\), and so need the data \[ {@tt@} \]</p>
<p>
Molar mass of \(\ce{@CN@}\).
\[
M=
[[define _first='true'/]][[foreach ex='CL']][[if test='not _first']] + [[else]][[define _first='false'/]][[/if]]
{@second(ex)@} \times {@dispsf(chem_data(first(ex),"AtomicMass"),3)@} \mathrm{g}\, \mathrm{mol}^{−1}
[[/foreach]]
= {@stack_units_nums(ta1)@} \mathrm{g}\, \mathrm{mol}^{−1}.
\]
</p>]]></text>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>0.1</penalty>
    <hidden>0</hidden>
    <idnumber/>
    <stackversion>
      <text>2025080100</text>
    </stackversion>
    <questionvariables>
      <text><![CDATA[stack_include_contrib("chemistry.mac");
stack_unit_si_declare(true);

/* Each element must be a list of atoms and numbers. */
CLL:[
     [["H",2],["O",1]],            /* Water */
     [["C",1],["O",2]],            /* Carbon dioxide */
     [["Ca",1],["C", 1], ["O",3]]  /* Calcium carbonate */
    ];
/* Choose one of these. */
CL:rand(CLL);
/* The CL list written as a single string. */
CN:apply(sconcat, map(lambda([ex], if is(second(ex)=1) then first(ex) else sconcat(first(ex),string(second(ex)))), CL));
/* Calculate the final answer. */
ta1:stackunits(dispsf(apply("+",map(lambda([ex],second(ex)*chem_data(first(ex),"AtomicMass")), CL)),3), chem_units("AtomicMass"));
/* Create a table of atomic masses of the elements used. */
/* Get unique elements in the formula CL. */
tt:setify(map(first, CL));
/* Make a list of list of values. */
tt:map(lambda([ex], [ex, dispsf(chem_data(ex,"AtomicMass"),3)]), listify(tt));
tt:apply(table, append([["Element", "Atomic Mass"]], tt));]]></text>
    </questionvariables>
    <specificfeedback format="html">
      <text>[[feedback:prt1]]</text>
    </specificfeedback>
    <questionnote format="html">
      <text>\(\require{mhchem} \ce{@CN@}\) has mass {@ta1@}.</text>
    </questionnote>
    <questiondescription format="html">
      <text><![CDATA[[[todo tags="4.11.0,chemistry"]]Once released, replace with stack_include_contrib("chemistry.mac"); in the question variables.[[/todo]]]]></text>
    </questiondescription>
    <questionsimplify>1</questionsimplify>
    <assumepositive>0</assumepositive>
    <assumereal>0</assumereal>
    <prtcorrect format="html">
      <text><![CDATA[<span style="font-size: 1.5em; color:green;"><i class="fa fa-check"></i></span> Correct answer, well done.]]></text>
    </prtcorrect>
    <prtpartiallycorrect format="html">
      <text><![CDATA[<span style="font-size: 1.5em; color:orange;"><i class="fa fa-adjust"></i></span> Your answer is partially correct.]]></text>
    </prtpartiallycorrect>
    <prtincorrect format="html">
      <text><![CDATA[<span style="font-size: 1.5em; color:red;"><i class="fa fa-times"></i></span> Incorrect answer.]]></text>
    </prtincorrect>
    <decimals>.</decimals>
    <scientificnotation>*10</scientificnotation>
    <multiplicationsign>dot</multiplicationsign>
    <sqrtsign>1</sqrtsign>
    <complexno>i</complexno>
    <inversetrig>cos-1</inversetrig>
    <logicsymbol>lang</logicsymbol>
    <matrixparens>[</matrixparens>
    <isbroken>0</isbroken>
    <variantsselectionseed/>
    <input>
      <name>ans1</name>
      <type>units</type>
      <tans>ta1</tans>
      <boxsize>15</boxsize>
      <strictsyntax>1</strictsyntax>
      <insertstars>0</insertstars>
      <syntaxhint/>
      <syntaxattribute>0</syntaxattribute>
      <forbidwords/>
      <allowwords/>
      <forbidfloat>1</forbidfloat>
      <requirelowestterms>0</requirelowestterms>
      <checkanswertype>0</checkanswertype>
      <mustverify>1</mustverify>
      <showvalidation>1</showvalidation>
      <options>minsf:3, maxsf:6,negpow</options>
    </input>
    <prt>
      <name>prt1</name>
      <value>1.0000000</value>
      <autosimplify>1</autosimplify>
      <feedbackstyle>1</feedbackstyle>
      <feedbackvariables>
        <text/>
      </feedbackvariables>
      <node>
        <name>0</name>
        <description/>
        <answertest>Units</answertest>
        <sans>ans1</sans>
        <tans>ta1</tans>
        <testoptions>3</testoptions>
        <quiet>0</quiet>
        <truescoremode>=</truescoremode>
        <truescore>1</truescore>
        <truepenalty/>
        <truenextnode>-1</truenextnode>
        <trueanswernote>prt1-1-T</trueanswernote>
        <truefeedback format="html">
          <text/>
        </truefeedback>
        <falsescoremode>=</falsescoremode>
        <falsescore>0</falsescore>
        <falsepenalty/>
        <falsenextnode>-1</falsenextnode>
        <falseanswernote>prt1-1-F</falseanswernote>
        <falsefeedback format="html">
          <text/>
        </falsefeedback>
      </node>
    </prt>
    <deployedseed>2138094012</deployedseed>
    <deployedseed>1336742253</deployedseed>
    <deployedseed>186464585</deployedseed>
    <qtest>
      <testcase>1</testcase>
      <description>Test case assuming the teacher's input gets full marks.</description>
      <testinput>
        <name>ans1</name>
        <value>ta1</value>
      </testinput>
      <expected>
        <name>prt1</name>
        <expectedscore>1.0000000</expectedscore>
        <expectedpenalty>0.0000000</expectedpenalty>
        <expectedanswernote>prt1-1-T</expectedanswernote>
      </expected>
    </qtest>
  </question>
</quiz>
