// Numbas version: finer_feedback_settings {"name": "Substitute random values into an expression variable", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Substitute random values into an expression variable", "tags": [], "metadata": {"description": "
Shows two different ways
", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "", "advice": "", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true, "j": false}, "constants": [], "variables": {"curly_braces": {"name": "curly_braces", "group": "Ungrouped variables", "definition": "expression(\"2{k}x\")", "description": "Substitute a variable into an expression using curly braces.
\nThis is convenient and Numbas does try its best to avoid errors due to the fact that the value is just substituted into a string, before the expression is parsed, but there might still be cases where it goes wrong.
", "templateType": "anything", "can_override": false}, "expr": {"name": "expr", "group": "Ungrouped variables", "definition": "expression(safe(\"2*a + k*x\"))", "description": "A generic expression. We'll substitute a value for $a$ into it.
", "templateType": "mathematical expression", "can_override": false}, "with_substitute": {"name": "with_substitute", "group": "Ungrouped variables", "definition": "substitute([a: k], expr)", "description": "Substitute a value into an expression with the substitute function.
This is a bit longer, but it's much more robust than string interpolation. Note that the question's variables aren't used, only the substitutions you explicitly give.
", "templateType": "anything", "can_override": false}, "k": {"name": "k", "group": "Ungrouped variables", "definition": "random(-10 .. 10#1)", "description": "", "templateType": "randrange", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["curly_braces", "expr", "with_substitute", "k"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}], "resources": []}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}