A function that returns True or False inside an if
Calls a function that returns True or False right inside an if condition. The indented code runs only when the function returns True, so no extra variable is needed.
Understanding A function that returns True or False inside an if in ACARA Digital Technologies Years 7–8
What it does: is_adult(age) returns True or False, so it works as the condition by itself. The name is_even says what the True/False answer means, so if is_even(n): reads like plain English. Use == to compare. A single = is for assigning a value to a variable, so it causes a syntax error here. 8 % 2 is 0, so 8 % 2 == 0 is True. The function returns a bool, not the number. is_even(7) returns False, so the indented print line is skipped. print() only shows the result on screen. The function gives back None, so an if would never run the way you want. Use return.
Common mistakes: A function definition line must end with a colon. It should be def is_even(n):. A function is called with round brackets, not square brackets. It should be if is_even(n):.
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 522–560) and word search (Modules 522–580).
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
if is_even(n):Fill in the Blanks
Spot the Error
Student with a class code? Join your class →