Order of operations and brackets

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Order of operations and brackets

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is the value of 2 + 3 * 4 in Cambridge pseudocode?
A 20
B 14
2. What is the value of (2 + 3) * 4?
A 14
B 20
3. Which operation is worked out first in 10 - 6 / 2?
A 6 / 2
B 10 - 6
4. Which expression correctly works out the average of two marks, a and b?
A (a + b) / 2
B a + b / 2
5. What does a + b / 2 do when a = 10 and b = 20?
A Gives 20, because only b is divided by 2
B Gives 15, because a + b is divided by 2

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
12 + 3 * 4 AAverage ← (Mark1 + Mark2) / 2
2(2 + 3) * 4 BWithout brackets, only Mark2 is divided by 2 and then added to Mark1, so this is not the average. It should be (Mark1 + Mark2) / 2.
3Brackets make the order explicit, so the addition happens before the division when finding an average of two marks CBrackets are worked out first, so the result is 5 * 4 = 20
4Multiplication is worked out before subtraction, so the multiplication in this expression is done first DMultiplication comes first, so this gives 14, not 20. To get 20, write (2 + 3) * 4.
5Average ← Mark1 + Mark2 / 2 EResult ← 10 - 2 * 3
6Total ← (2 + 3 * 4) should give 20 FMultiplication happens first, so the result is 2 + 12 = 14

Definitions

(a + b) / 2

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Average ← (Maths + English) _ 2
2.
Result ← 2 + 3 _ 4 OUTPUT Result // Output is 14
3.
Average ← (Test1 + Test2 + Test3) / 3 OUTPUT _______
4.
Average ← (Mark1 + Mark2 + Mark3) / _
5.
Result ← (10 - 4) _ 2 // Result is 3

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Average : REAL
B Average ← A + B / 2
C OUTPUT Average
Question 2
A DECLARE Result : INTEGER
B // add first, then multiply
C Result ← 2 + 3 * 4
D OUTPUT Result
Question 3
A DECLARE Mean : REAL
B Mean ← 10 + (20 + 30) / 3
C OUTPUT Mean
Question 4
A Price ← 8
B Cost ← (Price + 2 * 3
C OUTPUT Cost
Question 5
A Hours ← 8
B Extra ← 2
C Rate ← 12
D Pay ← Hours + Extra * Rate
E OUTPUT Pay

Answer Key

Order of operations and brackets
Section A: Quick Questions
Q1
B — 14
Q2
B — 20
Q3
A — 6 / 2
Q4
A — (a + b) / 2
Q5
A — Gives 20, because only b is divided by 2
Section B: Match the Pairs
Q1
2 + 3 * 4 → Multiplication happens first, so the result is 2 + 12 = 14
Q2
(2 + 3) * 4 → Brackets are worked out first, so the result is 5 * 4 = 20
Q3
Brackets make the order explicit, so the addition happens before the division when finding an average of two marks → Average ← (Mark1 + Mark2) / 2
Q4
Multiplication is worked out before subtraction, so the multiplication in this expression is done first → Result ← 10 - 2 * 3
Q5
Average ← Mark1 + Mark2 / 2 → Without brackets, only Mark2 is divided by 2 and then added to Mark1, so this is not the average. It should be (Mark1 + Mark2) / 2.
Q6
Total ← (2 + 3 * 4) should give 20 → Multiplication comes first, so this gives 14, not 20. To get 20, write (2 + 3) * 4.
Section C: Definitions
Q1
(a + b) / 2 — Brackets are worked out first, then * and / before + and -. So (a + b) / 2 adds first, then divides, giving an average. Without brackets, only b is divided by 2.
Section D: Fill in the Blanks
Q1
Average ← (Maths + English) / 2
Q2
Result ← 2 + 3 * 4 OUTPUT Result // Output is 14
Q3
Average ← (Test1 + Test2 + Test3) / 3 OUTPUT Average
Q4
Average ← (Mark1 + Mark2 + Mark3) / 3
Q5
Result ← (10 - 4) / 2 // Result is 3
Section E: Spot the Error
Q1
B — Without brackets, B / 2 is worked out first and then added to A, so this is not the average. It should be Average ← (A + B) / 2 so the addition happens first.
Q2
C — The comment says to add first, but without brackets 3 * 4 is done first, giving 14 instead of 20. The line should be Result ← (2 + 3) * 4.
Q3
B — The brackets are in the wrong place. All three numbers must be added before dividing by 3, so it should be Mean ← (10 + 20 + 30) / 3.
Q4
B — The opening bracket has no closing bracket. Brackets must come in matching pairs: Cost ← (Price + 2) * 3.
Q5
D — Without brackets, Extra * Rate is worked out first, so Hours is not paid at the rate. Pay should be (Hours + Extra) * Rate.