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: f = open("scores.txt") except FileNotFoundError: print("File missing") | ATyping text such as 'abc' causes a ValueError and the program crashes. The input needs validation or try/except so invalid input is handled. | |
| 2assert calc_total(2, 3) == 5 | Bwhile not age.isdigit(): age = input("Enter age: ") | |
| 3A reliable solution deals with invalid input by asking again rather than crashing | Cdef double(n): return n * 2 | |
| 4A reliable solution gives consistent results: the same input always produces the same output | DNo error handling: if data.txt is missing the program crashes with FileNotFoundError, so it is not reliable. Wrap it in try/except. | |
| 5f = open("data.txt") lines = f.read() | EHandles a missing file with an error message instead of crashing, which makes the solution more reliable | |
| 6age = int(input("Age: ")) | FA test that checks the function gives the correct result, helping confirm the solution is reliable |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
reliability — A solution is reliable when it behaves correctly and consistently every time it is used, even with invalid input or missing files or data. It handles errors without crashing.try:
f = open("scores.txt")
except FileNotFoundError:while not age.isdigit():
age = input("Age: ")assert average([2, 4, 6]) == 4try:
n = int(input("Number: "))
except ValueError:if os.path.exists("data.csv"):
f = open("data.csv")