// Numbas version: finer_feedback_settings {"name": "Avogadro's number", "extensions": ["eukleides", "random_person", "quantities"], "custom_part_types": [{"source": {"pk": 7, "author": {"name": "Christian Lawson-Perfect", "pk": 7}, "edit_page": "/part_type/7/edit"}, "name": "Quantity with units", "short_name": "quantity", "description": "

The student enters a quantity with units.

", "help_url": "https://github.com/numbas/numbas-extension-quantities", "input_widget": "string", "input_options": {"correctAnswer": "plain_string(settings[\"correctAnswer\"])", "hint": {"static": false, "value": "switch(\n settings[\"hint\"]=\"remind units\",\n \"Include units in your answer.\",\n settings[\"hint\"]=\"show units\",\n \"Give your answer in \"+units_string(settings[\"correctAnswer\"])\n ,\n \"\"\n)"}, "allowEmpty": {"static": true, "value": false}}, "can_be_gap": true, "can_be_step": true, "marking_script": "mark:\napply(valid_number);\napply(student_quantity);\napply(has_units);\napply(compatible);\ntry(\n correctif(close_enough),\n x,\n apply(student_quantity)\n);\napply(same_units)\n\ninterpreted_answer:\nstudent_quantity\n\nallowed_notation_styles:\n[\"plain\",\"en\"]\n\nmatch_student_number:\nmatchnumber(studentAnswer,allowed_notation_styles)\n\nstudent_number:\nmatch_student_number[1]\n\nraw_student_units:\ntry(\n quantity(studentAnswer[len(match_student_number[0])..len(studentAnswer)]),\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)\n\nstudent_units:\nif(compatible(raw_student_units,correct_units) or settings[\"incompatible_units_action\"]<>\"convert\",\n raw_student_units,\n correct_units\n)\n\nstudent_quantity:\napply(student_units);\ntry(\n student_number * student_units,\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)\n\ncorrect_quantity:\nsettings[\"correctAnswer\"]\n\ncompatible:\nif(compatible(raw_student_units,correct_quantity),\n true\n,\n let(message,\"Your answer does not have the correct dimensions.\",\n if(settings[\"incompatible_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n if(settings[\"incompatible_units_action\"]=\"convert\",\n incorrect(\"Your answer does not have the correct dimensions. It will be marked as if the correct dimensions were used, and then a penalty will be applied.\")\n ,\n incorrect(\"Your answer does not have the correct dimensions.\");\n end()\n )\n );\n false\n )\n)\n\ncorrect_units:\nunits(correct_quantity)\n\nsame_units:\nassert(raw_student_units=correct_units,\n let(\n message,if(settings[\"hint\"]=\"show units\",\"You did not give your answer in \"+units_string(correct_units)+\".\", \"Your answer is not in the expected units.\"),\n switch(\n settings[\"different_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n settings[\"different_units_action\"]=\"incorrect\",\n incorrect(message); \n warn(message);\n end()\n ,\n settings[\"different_units_action\"]=\"warn\",\n warn(message);\n multiply_credit(1-settings[\"different_units_penalty\"],message)\n ,\n settings[\"different_units_penalty\"]<1,\n multiply_credit(1-settings[\"different_units_penalty\"],message)\n ,\n false\n )\n );\n false\n)\n\nhas_units:\nassert(not unitless(student_quantity),\n assert(settings[\"allow_unitless\"],\n warn(\"You must include the units in your answer.\");\n fail(\"You did not include units in your answer.\")\n )\n)\n\ncan_compare:\ncompatible or settings[\"incompatible_units_action\"]=\"convert\"\n\nclose_enough:\nif(can_compare,\n student_quantity>=correct_quantity - wiggle \n and \n student_quantity<=correct_quantity + wiggle \n,\n false\n)\n\nwiggle:\nunits(correct_quantity)*abs(eval(settings[\"wiggle\"]))\n\nvalid_number:\nif(isNaN(student_number),\n warn(translate(\"part.numberentry.answer invalid\"));\n fail(translate(\"part.numberentry.answer invalid\"))\n,\n true\n )", "marking_notes": [{"name": "mark", "description": "This is the main marking note. It should award credit and provide feedback based on the student's answer.", "definition": "apply(valid_number);\napply(student_quantity);\napply(has_units);\napply(compatible);\ntry(\n correctif(close_enough),\n x,\n apply(student_quantity)\n);\napply(same_units)"}, {"name": "interpreted_answer", "description": "A value representing the student's answer to this part.", "definition": "student_quantity"}, {"name": "allowed_notation_styles", "description": "", "definition": "[\"plain\",\"en\"]"}, {"name": "match_student_number", "description": "", "definition": "matchnumber(studentAnswer,allowed_notation_styles)"}, {"name": "student_number", "description": "

The scalar part of the student's quantity

", "definition": "match_student_number[1]"}, {"name": "raw_student_units", "description": "

The units of the student's quantity, before converting.

", "definition": "try(\n quantity(studentAnswer[len(match_student_number[0])..len(studentAnswer)]),\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)"}, {"name": "student_units", "description": "

The units of the student's quantity.

\n

If the student used units incompatible with the units in the expected answer, and the \"what to do if incompatible units used\" option is set to \"mark as if correct units used\", the student's units are ignored and the expected units are used instead.

", "definition": "if(compatible(raw_student_units,correct_units) or settings[\"incompatible_units_action\"]<>\"convert\",\n raw_student_units,\n correct_units\n)"}, {"name": "student_quantity", "description": "

The student's answer, interpreted as a quantity.

\n

Marking fails if the student does not enter a valid quantity.

", "definition": "apply(student_units);\ntry(\n student_number * student_units,\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)"}, {"name": "correct_quantity", "description": "", "definition": "settings[\"correctAnswer\"]"}, {"name": "compatible", "description": "

Are the units of the student's quantity compatible with the units of the expected quantity?

", "definition": "if(compatible(raw_student_units,correct_quantity),\n true\n,\n let(message,\"Your answer does not have the correct dimensions.\",\n if(settings[\"incompatible_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n if(settings[\"incompatible_units_action\"]=\"convert\",\n incorrect(\"Your answer does not have the correct dimensions. It will be marked as if the correct dimensions were used, and then a penalty will be applied.\")\n ,\n incorrect(\"Your answer does not have the correct dimensions.\");\n end()\n )\n );\n false\n )\n)"}, {"name": "correct_units", "description": "", "definition": "units(correct_quantity)"}, {"name": "same_units", "description": "

/Are the student's quantity and the expected quantity in exactly the same units?

", "definition": "assert(raw_student_units=correct_units,\n let(\n message,if(settings[\"hint\"]=\"show units\",\"You did not give your answer in \"+units_string(correct_units)+\".\", \"Your answer is not in the expected units.\"),\n switch(\n settings[\"different_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n settings[\"different_units_action\"]=\"incorrect\",\n incorrect(message); \n warn(message);\n end()\n ,\n settings[\"different_units_action\"]=\"warn\",\n warn(message);\n multiply_credit(1-settings[\"different_units_penalty\"],message)\n ,\n settings[\"different_units_penalty\"]<1,\n multiply_credit(1-settings[\"different_units_penalty\"],message)\n ,\n false\n )\n );\n false\n)"}, {"name": "has_units", "description": "", "definition": "assert(not unitless(student_quantity),\n assert(settings[\"allow_unitless\"],\n warn(\"You must include the units in your answer.\");\n fail(\"You did not include units in your answer.\")\n )\n)"}, {"name": "can_compare", "description": "

Can the student's answer be compared with the correct answer? True if compatible units used, or \"mark as if correct units used\" selected.

", "definition": "compatible or settings[\"incompatible_units_action\"]=\"convert\""}, {"name": "close_enough", "description": "

Is the student's quantity within the allowed tolerance of the expected answer?

", "definition": "if(can_compare,\n student_quantity>=correct_quantity - wiggle \n and \n student_quantity<=correct_quantity + wiggle \n,\n false\n)"}, {"name": "wiggle", "description": "", "definition": "units(correct_quantity)*abs(eval(settings[\"wiggle\"]))"}, {"name": "valid_number", "description": "

Is the scalar part of the student's answer a valid number?

", "definition": "if(isNaN(student_number),\n warn(translate(\"part.numberentry.answer invalid\"));\n fail(translate(\"part.numberentry.answer invalid\"))\n,\n true\n )\n"}], "settings": [{"name": "correctAnswer", "label": "Correct answer", "help_url": "", "hint": "The expected quantity.", "input_type": "code", "default_value": "", "evaluate": true}, {"name": "hint", "label": "Input hint", "help_url": "", "hint": "", "input_type": "dropdown", "default_value": "remind units", "choices": [{"value": "none", "label": "None"}, {"value": "remind units", "label": "Remind to include units"}, {"value": "show units", "label": "Show required units"}]}, {"name": "allow_unitless", "label": "Allow unitless answer?", "help_url": "", "hint": "If not ticked, the student is prevented from submitting an answer without specifying units.", "input_type": "checkbox", "default_value": true}, {"name": "incompatible_units_action", "label": "What to do if incompatible units used", "help_url": "", "hint": "If the student's answer is given in units incompatible with the correct answer's units:
\n", "input_type": "dropdown", "default_value": "incorrect", "choices": [{"value": "incorrect", "label": "Mark as incorrect"}, {"value": "prevent", "label": "Prevent submission"}, {"value": "convert", "label": "Mark as if correct units used"}]}, {"name": "different_units_action", "label": "What to do if different units used", "help_url": "", "hint": "If the student's answer is given in different units to the expected answer:
\n", "input_type": "dropdown", "default_value": "convert", "choices": [{"value": "convert", "label": "Convert"}, {"value": "warn", "label": "Warn and convert"}, {"value": "prevent", "label": "Prevent submission"}, {"value": "incorrect", "label": "Mark incorrect"}]}, {"name": "different_units_penalty", "label": "Penalty if different units used", "help_url": "", "hint": "This penalty is applied if the student gives their answer in different units to the expected answer. The selected percentage of the student's score is taken away.", "input_type": "percent", "default_value": "100"}, {"name": "wiggle", "label": "Margin of error", "help_url": "", "hint": "The student's answer is marked correct if the difference between it and the correct answer is at most this value, measured in the same units as the correct answer.", "input_type": "mathematical_expression", "default_value": "10^-12", "subvars": true}], "public_availability": "always", "published": true, "extensions": ["quantities"]}], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"resources": [], "variables": {"moles": {"group": "Ungrouped variables", "description": "

Moles of carbon

", "templateType": "anything", "definition": "qty(random(0.25..2#0.25 except 1),\"mol\")", "name": "moles"}, "avogadro": {"group": "Ungrouped variables", "description": "", "templateType": "anything", "definition": "qty(dec(\"6.02214076e+23\"),\"1/mol\")", "name": "avogadro"}, "grams": {"group": "Ungrouped variables", "description": "

Number of grams of carbon

", "templateType": "anything", "definition": "c_mass*moles", "name": "grams"}, "c_mass": {"group": "Ungrouped variables", "description": "

Atomic mass of Carbon

", "templateType": "anything", "definition": "qty(12,\"g/mol\")", "name": "c_mass"}, "molecules": {"group": "Ungrouped variables", "description": "

Number of molecules of carbon

", "templateType": "anything", "definition": "avogadro*moles", "name": "molecules"}}, "variable_groups": [], "navigation": {"preventleave": false, "allowregen": true, "showfrontpage": false, "showresultspage": "never"}, "extensions": ["quantities"], "functions": {}, "parts": [{"customName": "", "correctAnswerFraction": false, "precisionMessage": "You have not given your answer to the correct precision.", "precisionType": "sigfig", "useCustomName": false, "customMarkingAlgorithm": "q: settings[\"maxvalue\"]", "showPrecisionHint": true, "correctAnswerStyle": "scientific", "showCorrectAnswer": true, "notationStyles": ["plain", "en", "si-en", "scientific"], "maxValue": "scalar(avogadro)", "precision": "3", "type": "numberentry", "minValue": "scalar(avogadro)", "extendBaseMarkingAlgorithm": true, "mustBeReducedPC": 0, "precisionPartialCredit": 0, "scripts": {}, "prompt": "

How many molecules are there in one mole of substance?

\n

Give your answer in scientific notation in the form NeP.

", "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "mustBeReduced": false, "marks": 1, "unitTests": [], "allowFractions": false, "strictPrecision": true, "variableReplacements": []}, {"customName": "", "showFeedbackIcon": true, "scripts": {}, "prompt": "

The atomic mass of carbon is 12. What is the mass of {moles} of carbon, in grams?

", "variableReplacementStrategy": "originalfirst", "useCustomName": false, "customMarkingAlgorithm": "", "unitTests": [], "settings": {"hint": "remind units", "allow_unitless": true, "wiggle": "10^-12", "correctAnswer": "grams", "different_units_action": "convert", "different_units_penalty": "100"}, "marks": 1, "extendBaseMarkingAlgorithm": true, "showCorrectAnswer": true, "type": "quantity", "variableReplacements": []}, {"customName": "", "correctAnswerFraction": false, "precisionMessage": "You have not given your answer to the correct precision.", "precisionType": "sigfig", "useCustomName": false, "customMarkingAlgorithm": "", "showPrecisionHint": true, "correctAnswerStyle": "plain", "showCorrectAnswer": true, "notationStyles": ["plain", "en", "si-en", "scientific"], "maxValue": "scalar(molecules)", "precision": "3", "type": "numberentry", "minValue": "scalar(molecules)", "extendBaseMarkingAlgorithm": true, "mustBeReducedPC": 0, "precisionPartialCredit": 0, "scripts": {}, "prompt": "

How many molecules are there in {moles} of carbon?

\n

Give your answer in scientific notation in the form NeP.

", "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "mustBeReduced": false, "marks": 1, "unitTests": [], "allowFractions": false, "strictPrecision": true, "variableReplacements": []}], "advice": "", "ungrouped_variables": ["avogadro", "c_mass", "moles", "grams", "molecules"], "rulesets": {}, "preamble": {"js": "", "css": ""}, "custom_part_types": [{"marking_script": "mark:\napply(student_quantity);\napply(has_units);\napply(compatible);\ntry(\n correctif(close_enough),\n x,\n apply(student_quantity)\n);\napply(same_units)\n\ninterpreted_answer:\nstudent_quantity\n\nallowed_notation_styles:\n[\"plain\",\"en\"]\n\nmatch_student_number:\nmatchnumber(studentAnswer,allowed_notation_styles)\n\nstudent_number:\nmatch_student_number[1]\n\nstudent_units:\ntry(\n quantity(studentAnswer[len(match_student_number[0])..len(studentAnswer)]),\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)\n\nstudent_quantity:\napply(student_units);\ntry(\n student_number * student_units,\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)\n\ncorrect_quantity:\nsettings[\"correctAnswer\"]\n\ncompatible:\nif(student_quantity<>false and compatible(student_quantity,correct_quantity),\n true\n,\n incorrect(\"Your answer does not have the correct dimensions.\");\n end();\n false\n)\n\ncorrect_units:\nunits(correct_quantity)\n\nsame_units:\nassert(units(student_quantity)=units(correct_quantity),\n let(\n message,if(settings[\"hint\"]=\"show units\",\"You did not give your answer in \"+units_string(correct_units)+\".\", \"Your answer is not in the expected units.\"),\n switch(\n settings[\"different_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n settings[\"different_units_action\"]=\"incorrect\",\n incorrect(message); \n warn(message);\n end()\n ,\n settings[\"different_units_action\"]=\"warn\",\n warn(message);\n multiply_credit(settings[\"different_units_penalty\"],message)\n ,\n settings[\"different_units_penalty\"]<1,\n multiply_credit(settings[\"different_units_penalty\"],message)\n ,\n false\n )\n );\n false\n)\n\nhas_units:\nassert(not unitless(student_quantity),\n assert(settings[\"allow_unitless\"],\n warn(\"You must include the units in your answer.\");\n fail(\"You did not include units in your answer.\")\n )\n)\n\nclose_enough:\nif(compatible,\n student_quantity>=correct_quantity - wiggle \n and \n student_quantity<=correct_quantity + wiggle \n,\n false\n)\n\nwiggle:\nunits(correct_quantity)*eval(settings[\"wiggle\"])", "description": "

The student enters a quantity with units. Their answer is marked correct if they give both the right amount and the right units.

", "short_name": "quantity", "marking_notes": [{"description": "This is the main marking note. It should award credit and provide feedback based on the student's answer.", "definition": "apply(student_quantity);\napply(has_units);\napply(compatible);\ntry(\n correctif(close_enough),\n x,\n apply(student_quantity)\n);\napply(same_units)", "name": "mark"}, {"description": "A value representing the student's answer to this part.", "definition": "student_quantity", "name": "interpreted_answer"}, {"description": "", "definition": "[\"plain\",\"en\"]", "name": "allowed_notation_styles"}, {"description": "", "definition": "matchnumber(studentAnswer,allowed_notation_styles)", "name": "match_student_number"}, {"description": "", "definition": "match_student_number[1]", "name": "student_number"}, {"description": "", "definition": "try(\n quantity(studentAnswer[len(match_student_number[0])..len(studentAnswer)]),\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)", "name": "student_units"}, {"description": "

The student's answer, interpreted as a quantity.

\n

Marking fails if the student does not enter a valid quantity.

", "definition": "apply(student_units);\ntry(\n student_number * student_units,\n message,\n warn(\"Your answer is not a valid quantity.\");\n fail(\"Your answer is not a valid quantity.\")\n)", "name": "student_quantity"}, {"description": "", "definition": "settings[\"correctAnswer\"]", "name": "correct_quantity"}, {"description": "

Are the units of the student's quantity compatible with the units of the expected quantity?

", "definition": "if(student_quantity<>false and compatible(student_quantity,correct_quantity),\n true\n,\n incorrect(\"Your answer does not have the correct dimensions.\");\n end();\n false\n)", "name": "compatible"}, {"description": "", "definition": "units(correct_quantity)", "name": "correct_units"}, {"description": "

Are the student's quantity and the expected quantity in exactly the same units?

", "definition": "assert(units(student_quantity)=units(correct_quantity),\n let(\n message,if(settings[\"hint\"]=\"show units\",\"You did not give your answer in \"+units_string(correct_units)+\".\", \"Your answer is not in the expected units.\"),\n switch(\n settings[\"different_units_action\"]=\"prevent\",\n warn(message);\n fail(message)\n ,\n settings[\"different_units_action\"]=\"incorrect\",\n incorrect(message); \n warn(message);\n end()\n ,\n settings[\"different_units_action\"]=\"warn\",\n warn(message);\n multiply_credit(settings[\"different_units_penalty\"],message)\n ,\n settings[\"different_units_penalty\"]<1,\n multiply_credit(settings[\"different_units_penalty\"],message)\n ,\n false\n )\n );\n false\n)", "name": "same_units"}, {"description": "", "definition": "assert(not unitless(student_quantity),\n assert(settings[\"allow_unitless\"],\n warn(\"You must include the units in your answer.\");\n fail(\"You did not include units in your answer.\")\n )\n)", "name": "has_units"}, {"description": "", "definition": "if(compatible,\n student_quantity>=correct_quantity - wiggle \n and \n student_quantity<=correct_quantity + wiggle \n,\n false\n)", "name": "close_enough"}, {"description": "", "definition": "units(correct_quantity)*eval(settings[\"wiggle\"])", "name": "wiggle"}], "public_availability": "restricted", "extensions": ["quantities"], "source": {"author": {"name": "Christian Lawson-Perfect", "pk": 1}, "edit_page": "/part_type/27/edit", "pk": 27}, "published": false, "input_options": {"hint": {"static": false, "value": "switch(\n settings[\"hint\"]=\"remind units\",\n \"Include units in your answer.\",\n settings[\"hint\"]=\"show units\",\n \"Give your answer in \"+units_string(settings[\"correctAnswer\"])\n ,\n \"\"\n)"}, "allowEmpty": {"static": true, "value": false}, "correctAnswer": "string(settings[\"correctAnswer\"])"}, "can_be_step": true, "can_be_gap": true, "help_url": "", "settings": [{"hint": "The expected quantity.", "label": "Correct answer", "evaluate": true, "input_type": "code", "help_url": "", "default_value": "", "name": "correctAnswer"}, {"hint": "", "label": "Input hint", "default_value": "remind units", "input_type": "dropdown", "help_url": "", "choices": [{"label": "None", "value": "none"}, {"label": "Remind to include units", "value": "remind units"}, {"label": "Show required units", "value": "show units"}], "name": "hint"}, {"hint": "If not ticked, the student is prevented from submitting an answer without specifying units.", "label": "Allow unitless answer?", "input_type": "checkbox", "help_url": "", "default_value": true, "name": "allow_unitless"}, {"hint": "If the student's answer is given in different units to the expected answer:
\n", "label": "What to do if different units used", "default_value": "convert", "input_type": "dropdown", "help_url": "", "choices": [{"label": "Convert", "value": "convert"}, {"label": "Warn and convert", "value": "warn"}, {"label": "Prevent submission", "value": "Prevent"}, {"label": "Mark incorrect", "value": "incorrect"}], "name": "different_units_action"}, {"hint": "This penalty is applied if the student gives their answer in different units to the expected answer. The selected percentage of the student's score is retained.", "label": "Penalty if different units used", "input_type": "percent", "help_url": "", "default_value": "100", "name": "different_units_penalty"}, {"hint": "The student's answer is marked correct if the difference between it and the correct answer is at most this value, measured in the same units as the correct answer.", "label": "Margin of error", "subvars": true, "input_type": "mathematical_expression", "help_url": "", "default_value": "10^-12", "name": "wiggle"}], "name": "Quantity", "input_widget": "string"}], "tags": [], "statement": "", "variablesTest": {"maxRuns": 100, "condition": ""}, "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "http://localhost:8000/accounts/profile/1/"}, {"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}], "metadata": {"description": "

The student is asked to give the Avogadro constant in scientific form, calculate the mass of a number of moles of carbon, in grams, and then calculate the number of molecules in that mass.

This is a demonstration of the high-precision decimal arithmetic in Numbas v4.0.

", "licence": "Creative Commons Attribution 4.0 International"}, "name": "Avogadro's number", "type": "exam"}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "http://localhost:8000/accounts/profile/1/"}, {"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}