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 | |
|---|---|---|
| 1while age < 0 or age > 120: | AAsks the user again inside the loop so they get another chance to enter a valid answer | |
| 2age = int(input("Try again: ")) | Bprint("Age must be 0 to 120") | |
| 3Show an error message each time the input is invalid so the user knows what went wrong | CThere is no new input inside the loop, so age never changes and the loop runs forever. Add age = int(input(...)) inside the loop. | |
| 4A range check that stays in the loop while a score is outside 1 to 10 | Dwhile score < 1 or score > 10: | |
| 5while age >= 0 and age <= 120: age = int(input("Age: ")) | EThe condition checks for VALID ages, so the loop runs when the input is good and stops when it is bad. It should loop while the age is invalid (age < 0 or age > 120). | |
| 6while age < 0 or age > 120: print("Invalid age") | FKeeps looping while the age is outside the allowed range of 0 to 120 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
while not valid: — A loop that keeps asking for input again until the answer is valid, so bad data (like an age of -5) can't get into your program. Show an error message each time.age = int(input("Enter age: "))
while age < 0 or age > 120:
age = int(input("Try again: "))age = int(input("Age: "))
while age < 0 or age > 120:
age = int(input("Age 0-120: "))while age < 0 or age > 120:
print("Invalid age. Try again.")
age = int(input("Age: "))while age < 0 or age > 120:
print("Age must be 0 to 120")
age = int(input("Try again: "))score = int(input("Score out of 10: "))
while score < 0 or score > 10:
score = int(input("Score out of 10: "))