← IGCSE Computer Science Paper 2

Brackets in pseudocode expressions

Brackets force the work inside to be done first, so A and B are added before dividing by 2. Without them, A + B / 2 divides B by 2 first. Use them in sums and AND/OR conditions.

Understanding Brackets in pseudocode expressions in IGCSE Computer Science Paper 2

What it does: / has higher priority than +, so B / 2 is calculated first and then A is added. This is not the average of A and B. Division is done before addition, so B / 2 = 5 first, then 6 + 5 = 11. The brackets make 6 + 10 = 16 happen first, then 16 / 2 = 8. The brackets add all three numbers before dividing by 3. Without them, only C is divided by 3. The brackets force A + B to be worked out before the division, so this correctly calculates the average of two values.

Common mistakes: Without brackets, Mark2 / 2 is done first and then added to Mark1. The addition must be done first, so it needs brackets: (Mark1 + Mark2) / 2. AND is done before OR, so this means (Vip AND Cash) OR Card. Anyone with Card would get in without being a Vip. The OR part needs brackets: Vip AND (Cash OR Card).

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 146–155) and word search (Modules 146–165).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which line correctly calculates the average of two marks, Mark1 and Mark2?
Average ← (Mark1 + Mark2) / 2Average ← Mark1 + Mark2 / 2
Matches
Average ← Total1 + Total2 / 2
↓
The brackets are missing, so only Total2 is divided by 2 and Total1 is added afterwards. It should be (Total1 + Total2) / 2.
Applying
Meanings
Term
(A + B) / 2
Meaning
Brackets force the work inside to be done first, so A and B are added before dividing by 2. Without them, A + B / 2 divides B by 2 first. Use them in sums and AND/OR conditions.
Practice
Average ← (Mark1 + Mark2) / 2
Testing
Gaps
Average ← Mark1 + Mark2) / 2
Check Answer
Spots
1Average ← Mark1 + Mark2 / 2
2OUTPUT Average

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Bear' badge — Forest Guardian, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line correctly calculates the average of two marks, Mark1 and Mark2?
A. Average ← (Mark1 + Mark2) / 2 ✓
B. Average ← Mark1 + Mark2 / 2
Without brackets, only Mark2 is divided by 2 and then Mark1 is added. Brackets make the addition happen first.
2. A is 6 and B is 10. What is the value of A + B / 2?
A. 8
B. 11 ✓
Division is done before addition, so B / 2 = 5 first, then 6 + 5 = 11.
3. A is 6 and B is 10. What is the value of (A + B) / 2?
A. 8 ✓
B. 11
The brackets make 6 + 10 = 16 happen first, then 16 / 2 = 8.
4. Which statement about brackets in an expression is correct?
A. The work inside the brackets is done first ✓
B. The work inside the brackets is done last
Brackets force the calculation inside them to be done first, before the rest of the expression.
5. Which condition checks that a person is 18 or over AND has a ticket or a pass?
A. Age >= 18 AND Ticket = TRUE OR Pass = TRUE
B. Age >= 18 AND (Ticket = TRUE OR Pass = TRUE) ✓
AND is worked out before OR. Without brackets, anyone with a pass would get in, even if under 18. The brackets make the OR happen first.

Match the Pairs

Average ← (A + B) / 2 → Adds A and B first because of the brackets, then divides the total by 2 to give the average
IF (Age > 12) AND (Age < 20) OR (Member = TRUE) THEN → Brackets group the parts of the condition so the order in which AND and OR are applied is clear
Without brackets, division is done before addition, so only B is divided by 2 → Result ← A + B / 2
Brackets make an average of three marks correct by adding all the marks before dividing → Average ← (Mark1 + Mark2 + Mark3) / 3
Average ← Total1 + Total2 / 2 → The brackets are missing, so only Total2 is divided by 2 and Total1 is added afterwards. It should be (Total1 + Total2) / 2.
IF Age < 12 OR Age > 65 AND Member = TRUE THEN → Without brackets, AND is worked out before OR, so the condition may not mean what was intended. Brackets are needed, such as (Age < 12 OR Age > 65) AND Member = TRUE.

Key Term

(A + B) / 2
Brackets force the work inside to be done first, so A and B are added before dividing by 2. Without them, A + B / 2 divides B by 2 first. Use them in sums and AND/OR conditions.

Fill in the Blanks

1. Average ← (Mark1 + Mark2) / 2
Hint: Type the symbol that makes the addition happen before the division.
2. Average ← (A + B + C) / 3
Hint: Type the arithmetic operator that divides the bracketed total to find the mean.
3. IF (Day = "Sat" OR Day = "Sun") AND Free = TRUE
Hint: Type the logical operator that joins the bracketed condition to the second condition.
4. DECLARE Average : REAL Average ← (Mark1 + Mark2) / 2
Hint: Type the number that the bracketed total is divided by, matching how many marks there are.
5. IF Age > 15 AND (Pass OR Paid) THEN
Hint: Type the symbol that groups the OR condition so it is evaluated first.

Spot the Error

Question 1
A Average ← Mark1 + Mark2 / 2
B OUTPUT Average
C OUTPUT Mark1, Mark2
Line A — Without brackets, Mark2 / 2 is done first and then added to Mark1. The addition must be done first, so it needs brackets: (Mark1 + Mark2) / 2.
Question 2
A INPUT Vip, Cash, Card
B // must pay by Cash or Card
C IF Vip AND Cash OR Card THEN
D OUTPUT "Entry"
E ENDIF
Line C — AND is done before OR, so this means (Vip AND Cash) OR Card. Anyone with Card would get in without being a Vip. The OR part needs brackets: Vip AND (Cash OR Card).
Question 3
A INPUT A, B, C
B Mean ← (A + B + C / 3)
C OUTPUT Mean
Line B — The bracket closes in the wrong place, so only C is divided by 3 and then added to A and B. The closing bracket should come before the division: (A + B + C) / 3.
Question 4
A Price ← 20
B Disc ← 5
C Qty ← 2
D Cost ← Price - Disc * Qty
E OUTPUT Cost
Line D — Multiplication is done before subtraction, so only Disc is multiplied by Qty. The discount must be taken off first, so it needs brackets: (Price - Disc) * Qty.
Question 5
A INPUT X
B // X must be from 1 to 10
C Valid ← TRUE
D IF NOT X > 0 AND X < 11 THEN
E Valid ← FALSE
F ENDIF
Line D — Without brackets, NOT applies only to X > 0, not to the whole range check. The whole condition must be in brackets: NOT (X > 0 AND X < 11).

Student with a class code? Join your class →