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 | |
|---|---|---|
| 1def get_valid_age(): | AThe function prints the age instead of returning it, so the caller gets no checked value back. Use return age. | |
| 2return age | Bif text == "": return False | |
| 3Run the checks in order: existence first, then type, then range | CThe type check (int) runs before the existence check, so empty input crashes with an error. Check that the input exists first. | |
| 4Reuse the same function for each input | DSends the checked age back to the code that called the function once it has passed every check | |
| 5age = int(text) if text == "": return False | EDefines a reusable function that bundles all the age checks together so they can be called for every input | |
| 6def get_valid_age(): age = int(input("Age: ")) if 0 <= age <= 120: print(age) | Fage2 = get_valid_age() |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
def get_valid_age(): — A function that runs existence, type and range checks in order, then returns a valid age (or True/False) so you can reuse the same checks for every input.age = input("Age: ")
if age == "":
return Falseage = input("Age: ")
if not age.isdigit():
return Falseage = int(age)
if age < 0 or age > 120:
return Falseif 0 <= age <= 120:
return age
return Falsefirst = get_valid_age()
second = get_valid_age()
print(first + second)