Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Functions that return True or False (Python) worksheet is part of the ACARA Digital Technologies Years 9–10 — Modular and Object-Oriented Programming (Python) journey. Print it as a booklet?
Shade in the A or B circle for each question.
if not is_even(7): do?Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1def is_even(n): return n % 2 == 0 | AThe function prints the result instead of returning it, so the call gives None and an if cannot use it. Use return instead of print. | |
| 2if is_even(n): | Bdef is_adult(age): return age >= 18 | |
| 3A Boolean function can return the result of a comparison directly, with no if needed | CCalls a function that returns True or False and uses the result directly as the if condition. | |
| 4Boolean functions can be combined in one condition with not, and, or | DComparing the result to True is unnecessary. The function already returns a Boolean, so write if is_even(n): instead. | |
| 5if is_even(n) == True: print("Even") | Eif is_even(n) and not is_negative(n): | |
| 6def is_even(n): print(n % 2 == 0) | FDefines a Boolean function that returns True when n is even and False when it is odd. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if is_even(n): — Calls a function that returns True or False and uses that result directly as the if condition. You do not need to write == True. It can also be combined with not, and, or.def adult(age):
return age >= 18
print(adult(20))def even(n): return n % 2 == 0
if even(8):
print('Even number')def even(n): return n % 2 == 0
if not even(7):
print('Odd')def adult(age): return age >= 18
ticket = True
if adult(20) and ticket: print('Enter')def even(n): return n % 2 == 0
n = 7
while not even(n): n += 1