← ACARA Digital Technologies Years 7–8

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):.

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 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.

Learning
Duo
Which function body correctly checks if a number is even and returns a bool?
def is_even(n): return n % 2 = 0def is_even(n): return n % 2 == 0
Matches
if is_even == True: print("Even")
↓
The brackets and argument are missing, so the function is not called. is_even is just the function itself, not its True/False answer.
Applying
Meanings
Term
if is_even(n):
Meaning
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.
Practice
def is_even(n):
Testing
Gaps
iseven(n):
Check Answer
Spots
1def is_even(n)
2 return n % 2 == 0

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

The 'Scorpion' badge — Venom Debugger, 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 function body correctly checks if a number is even and returns a bool?
A. def is_even(n): return n % 2 == 0 ✓
B. def is_even(n): return n % 2 = 0
Use == to compare. A single = is for assigning a value to a variable, so it causes a syntax error here.
2. Which if line calls a yes/no function directly in the condition?
A. if is_even(n): ✓
B. if is_even(n) == True or False:
is_even(n) already gives back True or False, so you can put it straight in the if. Adding 'or False' is wrong and does nothing useful.
3. What does is_even(8) give back?
A. True ✓
B. 8
8 % 2 is 0, so 8 % 2 == 0 is True. The function returns a bool, not the number.
4. Which name is best for a function that answers a yes/no question about a number?
A. even_number_stuff
B. is_even ✓
Yes/no functions are often named starting with is_ so the if line reads like English: if is_even(n).
5. n is 7. What happens with this code? if is_even(n): print('Even')
A. Even is printed
B. Nothing is printed ✓
is_even(7) returns False, so the indented print line is skipped.

Match the Pairs

return n % 2 == 0 → Gives back True when n is even and False when it is odd, so the function can be used as a yes/no check
if is_even(n): → Calls the function inside the if condition; the indented code runs only when it returns True
A function that returns a bool can be called directly in an if condition, with no extra variable → if is_adult(age): print("Welcome")
A good name for a yes/no function starts with is_ so the if line reads like a question → def is_even(n): return n % 2 == 0
if is_even == True: print("Even") → The brackets and argument are missing, so the function is not called. is_even is just the function itself, not its True/False answer.
def is_even(n): print(n % 2 == 0) → The function prints the result instead of returning it, so it gives back None and the if never sees True.

Key Term

if is_even(n):
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.

Fill in the Blanks

1. def is_even(n): return n % 2 == 0
Hint: Type the keyword that starts a function definition. This yes/no function returns the result of a comparison.
2. if is_even(n): print("n is even")
Hint: Type the name of the yes/no function that is called inside the if condition to check the number.
3. if is_even(n): print("Even")
Hint: Type the keyword that starts a decision and uses the function result as its condition.
4. while not is_even(n): n = n + 1
Hint: Type the keyword that flips True and False, so the loop runs while the function returns False.
5. age = 20 if is_adult(age): print("Welcome")
Hint: Type a clear yes/no function name that asks whether the person is an adult. It starts with the word used for yes/no names.

Spot the Error

Question 1
A def is_even(n)
B return n % 2 == 0
C num = 8
D if is_even(num):
E print("Even")
Line A — A function definition line must end with a colon. It should be def is_even(n):
Question 2
A def is_even(n):
B return n % 2 == 0
C n = 6
D if is_even[n]:
E print("Even")
Line D — A function is called with round brackets, not square brackets. It should be if is_even(n):
Question 3
A def is_adult(age):
B return age >= 18
C if is_adult:
D print("Adult")
Line C — The function is never called because the brackets and the argument are missing. It should be if is_adult(20):
Question 4
A def is_even(n):
B result = n % 2 == 0
C print(result)
D if is_even(10):
E print("Even")
Line C — The function prints the answer but gives nothing back, so the if gets None and never runs. It should be return result.
Question 5
A def is_even(n):
B return n % 2 = 0
C for i in range(1, 5):
D if is_even(i):
E print(i)
Line B — A single = assigns a value. To compare, use ==. It should be return n % 2 == 0

Student with a class code? Join your class →