// Numbas version: exam_results_page_options {"name": "Keith's copy of Convert from one metric unit to another", "extensions": ["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.

The scalar part of the student's quantity

", "definition": "match_student_number"}, {"name": "raw_student_units", "description": "

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

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
\n
• \"Prevent submission\": Prevent the student from submitting until they use compatible units
• \n
• \"Mark as incorrect\": Mark the student's answer as incorrect.
• \n
• \"Mark as if correct units used\": Mark the student's answer as if they used the correct units, and apply the \"different units used\" penalty.
• \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
\n
• \"Convert\" - silently convert the student's answer to the units used in the correct answer.
• \n
• \"Warn and convert\" - show a warning to the student, but convert.
• \n
• \"Prevent submission\" - don't allow the student to submit, and show a warning that they must use the same units.
• \n
• \"Mark incorrect\" - the student's answer is marked as incorrect.
• \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}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variables": {"to_amount": {"group": "Ungrouped variables", "description": "", "templateType": "anything", "definition": "as(from_amount,to_unit)", "name": "to_amount"}, "units": {"group": "Ungrouped variables", "description": "

Some sets of units that you might reasonably convert between. A set of units is randomly picked, and then shuffled. The first item in the list is the \"from\" unit, and the second item is the \"to\" unit.

", "templateType": "anything", "definition": "shuffle(random([\n [\"g\",\"kg\"],\n [\"m\",\"cm\",\"mm\",\"km\"],\n [\"l\",\"ml\",\"cl\"]\n]))", "name": "units"}, "amount": {"group": "Ungrouped variables", "description": "

The amount of the \"to\" unit to use.

\n

Picked to use a variety of different precisions and orders of magnitude. If the step size was always 0.01, you'd very rarely get a round number or multiple of 10, so instead we pick a step size at random.

", "templateType": "anything", "definition": "random(10..random(100, 1000) # random(1, 0.1, 0.01, 10))", "name": "amount"}, "from_unit": {"group": "Ungrouped variables", "description": "

The unit the amount is given to the student in.

", "templateType": "anything", "definition": "qty(units)", "name": "from_unit"}, "q": {"group": "Ungrouped variables", "description": "", "templateType": "anything", "definition": "units(to_amount)*10^-12", "name": "q"}, "to_unit": {"group": "Ungrouped variables", "description": "

The unit the student must convert to.

", "templateType": "anything", "definition": "qty(units)", "name": "to_unit"}, "scale": {"group": "Ungrouped variables", "description": "

The number of \"from\" units in the \"to\" unit

", "templateType": "anything", "definition": "abs(to_unit/from_unit)", "name": "scale"}, "from_amount": {"group": "Ungrouped variables", "description": "

The amount to display to the student.

", "templateType": "anything", "definition": "precround(amount * scale * from_unit,9)", "name": "from_amount"}}, "name": "Keith's copy of Convert from one metric unit to another", "statement": "", "variablesTest": {"maxRuns": 100, "condition": ""}, "parts": [{"customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "unitTests": [], "marks": 0, "type": "gapfill", "showFeedbackIcon": true, "sortAnswers": false, "variableReplacements": [], "showCorrectAnswer": true, "gaps": [{"variableReplacements": [], "showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "unitTests": [], "marks": 1, "customMarkingAlgorithm": "", "scripts": {}, "settings": {"different_units_action": "incorrect", "hint": "none", "correctAnswer": "to_amount", "wiggle": "10^-12", "allow_unitless": true, "different_units_penalty": "100"}, "type": "quantity", "showFeedbackIcon": true, "extendBaseMarkingAlgorithm": true}], "prompt": "

Write $\\var{from_amount}$ in {units_string(to_unit)}.

\n

$\\var{from_amount} =$ []

", "scripts": {}, "extendBaseMarkingAlgorithm": true}], "tags": [], "ungrouped_variables": ["units", "from_unit", "to_unit", "scale", "amount", "from_amount", "to_amount", "q"], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

Convert a metric measurement to another order of magnitude, e.g. g to kg.

"}, "rulesets": {}, "preamble": {"css": "", "js": ""}, "variable_groups": [], "functions": {}, "extensions": ["quantities"], "advice": "

There are $\\var{(from_unit/to_unit) * units(to_unit)}$ in $\\var{units(from_unit)}$.

\n

To convert $\\var{from_amount}$ to {units_string(to_unit)}, multiply by {1/scale}:

\n

\$\\var{abs(from_amount)} \\times \\var{1/scale} = \\var{abs(to_amount)} \$

\n

So $\\var{from_amount} = \\var{to_amount}$.

", "type": "question", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Keith Tarnowski", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3425/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Keith Tarnowski", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3425/"}]}