Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1return n % 2 == 0 | ACalls the function inside the if condition; the indented code runs only when it returns True | |
| 2if is_even(n): | BThe brackets and argument are missing, so the function is not called. is_even is just the function itself, not its True/False answer. | |
| 3A function that returns a bool can be called directly in an if condition, with no extra variable | CThe function prints the result instead of returning it, so it gives back None and the if never sees True. | |
| 4A good name for a yes/no function starts with is_ so the if line reads like a question | DGives back True when n is even and False when it is odd, so the function can be used as a yes/no check | |
| 5if is_even == True: print("Even") | Eif is_adult(age): print("Welcome") | |
| 6def is_even(n): print(n % 2 == 0) | Fdef is_even(n): return n % 2 == 0 |
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 right inside an if condition. The indented code runs only when the function returns True, so no extra variable is needed.def is_even(n):
return n % 2 == 0if is_even(n):
print("n is even")if is_even(n):
print("Even")while not is_even(n):
n = n + 1age = 20
if is_adult(age):
print("Welcome")