Side effects and pure functions
A change a function makes outside itself, like printing, editing a global or changing a passed-in list. A pure function has no side effects and only returns a result from its inputs.
Understanding Side effects and pure functions in WA Computer Science ATAR Unit 1
What it does: The global keyword lets the function change score outside itself, which is a side effect. A pure function can be checked with one call and an expected value, with no setup or hidden state. append() mutates the original list. Using + builds a new list and returns it, leaving the original unchanged. It has no printing, globals or mutation, so the same input always gives the same output. The function mutates its input, so the caller's list changes even though a value is returned.
Common mistakes: Printing is a side effect, and the function now returns None. A pure function should use 'return price + tax' so the caller gets the result. A pure function gets its input through parameters. Without the 'score' parameter it depends on a global variable, and the call add_point(score) on line 4 would raise a TypeError. The header should be 'def add_point(score):'.
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 100–314) and word search (Modules 100–470).
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
side effectFill in the Blanks
Spot the Error
Student with a class code? Join your class →