// Numbas version: finer_feedback_settings {"name": "Basic R: Part 4", "duration": 0, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "allQuestions": true, "shuffleQuestions": false, "percentPass": 0, "timing": {"allowPause": true, "timeout": {"action": "none", "message": ""}, "timedwarning": {"action": "none", "message": ""}}, "pickQuestions": 0, "navigation": {"onleave": {"action": "none", "message": ""}, "reverse": true, "allowregen": true, "showresultspage": "oncompletion", "preventleave": true, "browse": true, "showfrontpage": true}, "feedback": {"showtotalmark": true, "advicethreshold": 0, "allowrevealanswer": true, "feedbackmessages": [], "showactualmark": true, "showanswerstate": true, "intro": "", "enterreviewmodeimmediately": true, "showexpectedanswerswhen": "inreview", "showpartfeedbackmessageswhen": "always", "showactualmarkwhen": "always", "showtotalmarkwhen": "always", "showanswerstatewhen": "always", "showadvicewhen": "never"}, "type": "exam", "questions": [], "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": [{"name": "Question 17 function", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "functions": {}, "ungrouped_variables": ["x", "a"], "tags": [], "preamble": {"css": "", "js": ""}, "advice": "
a) In the first part, the function takes the value $\\var{a}$ as input, and returns $\\var{2*a}$, the value multiplied by $2$.
\nb) In the second part, the function takes $y = \\var{2*a}$ as input (set in part a) and again returns the value multiplied by $2$.
", "rulesets": {}, "parts": [{"displayColumns": 0, "prompt": "What is the value of $y$?
", "matrix": [0, 0, "1", 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["{2*x}
", "2
", "{2*a}
", "{x}
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}, {"displayColumns": 0, "prompt": "What is the value of $z$?
", "matrix": ["1", 0, 0, 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["{4*a}
", "{4*x}
", "{2*x}
", "{2*a}
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}], "statement": "> x = {x}", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "variables": {"a": {"definition": "random(6..15#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "a", "description": ""}, "x": {"definition": "random(1..5#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "x", "description": ""}}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}]}, {"name": "Question 18 function", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "functions": {}, "ungrouped_variables": ["x", "z", "a"], "tags": [], "preamble": {"css": "", "js": ""}, "advice": "
> fun1 = function(x) {
+ return(2*x)
+ }
> (y= fun1({a}))
> (z= fun1(y))
a) This function takes a value, in this case $\\var{a}$ and multiplies it by a value $z$ which in this case is $\\var{z}$. Therefore our function gives $\\var{a}\\times\\var{z}=\\var{a*z}$.
\nb) $x$ has been defined in line 1 and should not be confused with the argument to the function. So, taking the input $\\var{x}$, the function returns $\\var{x}\\times\\var{z}=\\var{x*z}$.
", "rulesets": {}, "parts": [{"displayColumns": 0, "prompt": "What is the value of $y$?
", "matrix": [0, 0, "1", 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["{x}
", "{{x}*{z}}
", "{{a}*{z}}
", "{a}
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}, {"displayColumns": 0, "prompt": "What is the value of $a$?
", "matrix": [0, "1", 0, 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["{{x}*{a}}
", "{{x}*{z}}
", "{x}
", "{z}
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}], "statement": "> x = {x}", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "variables": {"a": {"definition": "random(6..10#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "a", "description": ""}, "x": {"definition": "random(-10..-1#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "x", "description": ""}, "z": {"definition": "random(2..10#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "z", "description": ""}}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}]}, {"name": "Question 19 function", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "functions": {}, "ungrouped_variables": ["a", "x", "b", "k"], "tags": [], "preamble": {"css": "", "js": ""}, "advice": "
> fun1 = function(x) {
+ z = {z}
+ return (x*z)
+ }
> y = fun1({a})
> a = fun1(x)
Don't be confused by the function stating $x=\\var{x}$. This just represents the default of the function. So if you type fun1(), the function will set $x=\\var{x}$ and return ${\\var{b*x}}$.
\na) Our function returns $\\var{b}\\times\\var{a}=\\var{a*b}$.
\nb) We are given $k=\\var{k}$. Our function takes $\\var{b}\\times k =\\var{b*k}$ as input and returns $\\var{b*k}\\times\\var{b}=\\var{k*b*b}$.
", "rulesets": {}, "parts": [{"displayColumns": 0, "prompt": "What is the value of $y$?
", "matrix": [0, 0, "1", 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["{x}
", "{{x}*{b}}
", "{{b}*{a}}
", "{{x}*{a}}
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}, {"displayColumns": 0, "prompt": "What is the value of $z$?
", "matrix": ["1", 0, 0, 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["{{b}*{b}*{k}}
", "{{b}*{k}}
", "{{k}*{a}}
", "{x}
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}], "statement": "> fun1 = function(x={x}) {", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "variables": {"a": {"definition": "random(5..10#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "a", "description": ""}, "x": {"definition": "random(-5..-1#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "x", "description": ""}, "k": {"definition": "random(2..4#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "k", "description": ""}, "b": {"definition": "random(2..4#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "b", "description": ""}}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question"}, {"name": "Question 20 TRUE/FALSE function", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "functions": {}, "ungrouped_variables": ["a", "b"], "tags": [], "preamble": {"css": "", "js": ""}, "advice": "
+ return({b}*x)
+ }
> y = fun1({a})
> k = {k}
> z = fun1({b}*k)
This function sets y = FALSE
if x = {b}
, or y = TRUE
if x is unequal to {b}. Line 1 sets x = {a}
, therefore y = TRUE
.
What is the value of $y$?
", "matrix": ["1", 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["TRUE
FALSE
> x = {a}", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "variables": {"a": {"definition": "random(1..5#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "a", "description": ""}, "b": {"definition": "random(6..10#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "b", "description": ""}}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}]}, {"name": "Question 21 else if functions", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "functions": {}, "ungrouped_variables": ["a", "b"], "tags": [], "preamble": {"css": "", "js": ""}, "advice": "
> if(x=={b}) {
y = FALSE
} else {
y = TRUE
}
The conditional statement returns:
\n$y=0$ of $x$ is greater than {a};
\n$y=1$ if $x$ is less than or equal to {b};
\n$y=2$ otherwise.
", "rulesets": {}, "parts": [{"distractors": ["", "", ""], "prompt": "What is the value of $y$?
", "matrix": [0, "1", 0], "shuffleChoices": true, "variableReplacements": [], "choices": ["0
", "1
", "2
"], "variableReplacementStrategy": "originalfirst", "displayType": "radiogroup", "maxMarks": 0, "marks": 0, "scripts": {}, "displayColumns": 0, "showCorrectAnswer": true, "type": "1_n_2", "minMarks": 0}], "statement": "> x = {b}", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "variables": {"a": {"definition": "random(7..11#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "a", "description": ""}, "b": {"definition": "random(1..5#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "b", "description": ""}}, "metadata": {"notes": "", "description": "", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}]}, {"name": "Question 22 else if ", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "functions": {}, "ungrouped_variables": ["x", "a"], "tags": [], "preamble": {"css": "", "js": ""}, "advice": "
> if(x > {a}) {
y = 0
} else if(x <= {b}) {
y = 1
} else {
y = 2
}
We are given that $x=\\var{x}$, which does not fit the criteria for $z=0$ or $z=1$ as these are both ranges that do not include $x=\\var{x}$.
", "rulesets": {}, "parts": [{"displayColumns": 0, "prompt": "What is the value of $z$?
", "matrix": [0, 0, "1"], "shuffleChoices": false, "variableReplacements": [], "choices": ["0
", "1
", "2
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}], "statement": "> x = {x}", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "variables": {"a": {"definition": "random(1..5#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "a", "description": ""}, "x": {"definition": "random(1..10#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "x", "description": ""}}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}]}, {"name": "Question 23 summation for loop", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "functions": {}, "ungrouped_variables": ["a"], "tags": [], "preamble": {"css": "", "js": ""}, "advice": "
> y = \"Male\"
> if(x > {{x}+{a}} & y == \"Female\"){
z = 0
} else if(x < {x} & y == \"Male\"){
z = 1
} else {
z = 2
}
This for loop takes the value 'total' and adds $1$ to it everytime. It loops $\\var{a}$ times, with the beginning value of $0$.
\nSo it will go...
\n0 + 1 = 1
\n1 + 1 = 2
\n2 + 1 = 3
\netc ...
\nTherefore the final value for 'total' must be $\\var{a}$.
", "rulesets": {}, "parts": [{"displayColumns": 0, "prompt": "What is the value of $x$?
", "matrix": [0, "1", 0, 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["0
", "{a}
", "{{a}+1}
", "{{a}*{a}}
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}], "statement": "> total = 0", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "variables": {"a": {"definition": "random(6..15#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "a", "description": ""}}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}]}, {"name": "Question 24 for loop ", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "functions": {}, "ungrouped_variables": ["a", "b"], "tags": [], "preamble": {"css": "", "js": ""}, "advice": "
> for(blob in 1:{a}){
total = total + 1
}
> x = total
This function initialises the variable 'total' to 0, and then increments its value by 1 each time that 'blob' is greater than {{a}-{b}}. Therefore it's value will be $\\var{a} - \\var{a-b}= \\var{b}$
", "rulesets": {}, "parts": [{"displayColumns": 0, "prompt": "What is the value of $x$?
", "matrix": [0, 0, "1", 0], "shuffleChoices": false, "variableReplacements": [], "choices": ["{a}
", "{{a}-{b}}
", "{b}
", "{{b}-1}
"], "variableReplacementStrategy": "originalfirst", "maxMarks": "1", "distractors": ["", "", "", ""], "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "1_n_2", "displayType": "radiogroup", "minMarks": 0}], "statement": "> total = 0", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "variables": {"a": {"definition": "random(10..20#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "a", "description": ""}, "b": {"definition": "random(3..9#1)", "templateType": "randrange", "group": "Ungrouped variables", "name": "b", "description": ""}}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}]}]}], "contributors": [{"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Amy Chadwick", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/505/"}], "extensions": [], "custom_part_types": [], "resources": []}
> for(blob in 1:{a}){
if(blob > {{a}-{b}}) {
total = total + 1
}
}
> x = total