Code
total = 0
repeat 8 times: total = total + 5
print(total)
Grade 9 · Math · Unit 9 of 15
Predict what the code does
Reading short programs with variables, loops, if statements and functions, predicting the output, and changing a parameter to get a new result. No typing is needed; the code is written in plain pseudocode.
Ontario Curriculum expectation: C2.1, C2.2, C2.3 · reading and altering code with variables, equations and inequalities
A taste of this unit. In the app, questions change every time and get easier or harder to match your child.
Question 1
What does this code print?
total = 0
repeat 8 times: total = total + 5
print(total)
answer box
40
Hint: The loop adds 5 a total of 8 times: 8 × 5 = 40.
Question 2
What does this code print?
x = 3
y = 5 * x + 7
print(y)
answer box
22
Hint: x is 3, so y = 5 × 3 + 7 = 22.
Question 3
Which line of code stores the cost of n tickets that cost $17 each?
cost = 17 * n
Hint: Cost is the price times the number of tickets. The variable being created goes on the left of the equals sign.
Question 4
What does this code print?
x = 11
print(x + 4 < 15)
false
Hint: 11 + 4 = 15, and 15 < 15 is false.
Question 5
What does this code print?
define area(w, h): return w * h
print(area(3, 9))
answer box
27
Hint: area(3, 9) returns 3 × 9 = 27.
Question 6
What does this code print?
x = 19
if x > 15: print("big")
otherwise: print("small")
big
Hint: 19 > 15 is true, so the code prints "big".