Order of operations with brackets in Python
Python works out brackets first, so (a + b) / 2 adds a and b before dividing by 2. Without the brackets, the division would happen first and the average would be wrong.
Understanding Order of operations with brackets in Python in VCE Software Development U4O1
What it does: The brackets make 3 + 4 happen first, giving 7, then 7 * 2 gives 14. Without brackets the answer would be 11. Multiplication comes before addition, so 3 * 4 = 12 and then 2 + 12 = 14. Python does b / 2 first. The fix is total = (a + b) / 2. Brackets are worked out first, so the addition happens before the division. This is the correct way to average two values. The brackets are in the right place, but the divisor must match how many values are added: (a + b + c) / 3.
Common mistakes: Without brackets, Python divides b by 2 first and then adds a, so the result is 125.0, not 85.0. It should be average = (a + b) / 2. Multiplication happens before addition, so this gives 11, not 16. Brackets are needed to add first: total = (5 + 3) * 2.
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 3–79) and word search (Modules 3–114).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
(a + b) / 2Fill in the Blanks
Spot the Error
Student with a class code? Join your class →