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 | |
|---|---|---|
| 1try: age = int(input()) except ValueError: print('Enter a number') | AKeeps asking until the input is valid, so bad data never gets used | |
| 2while age < 0 or age > 120: age = int(input('Age: ')) | BTyping letters such as 'abc' causes a ValueError and crashes the program, because there is no error handling. | |
| 3Reliability: the program gives the right result every time it is run with valid input | Cdef add(a, b): return a + b | |
| 4Handling invalid input: check the input before using it | DCatches bad input so the program shows a message instead of crashing | |
| 5age = int(input('Age: ')) print(age + 1) | Eif not name.isdigit(): print('Numbers only') | |
| 6try: n = int(input()) except: pass | FThe error is silently ignored, so n is never set and the program fails later without telling the user what went wrong. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
dependability — A dependable program works correctly and reliably every time, even when users enter unexpected or invalid input, because it handles errors instead of crashing.try:
n = int(input("Number: "))
except ValueError:try:
n = int(input("Number: "))
except ValueError:age = int(input("Age: "))
while age < 0:
age = int(input("Age: "))if count != 0:
print(total / count)except ValueError:
print("Please enter a number")