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 | |
|---|---|---|
| 1average = total / count | ARaises ZeroDivisionError if count is 0, for example when the user enters 0 or a list is empty | |
| 2remainder = 17 % 0 | Bif count != 0: avg = total / count | |
| 3Guard against dividing by zero with an if check before the division | Ctry: avg = total / count except ZeroDivisionError: avg = 0 | |
| 4Catch a divide by zero error with try/except so the program does not crash | DThe check is the wrong way round. The division only runs when count is 0, which guarantees the error. It should be if count != 0. | |
| 5n = int(input('Divide by: ')) print(100 / n) | EThe user could type 0, and the program never checks n before dividing, so it crashes with ZeroDivisionError. Add a check such as if n != 0. | |
| 6if count == 0: avg = total / count | FRaises ZeroDivisionError because the remainder operator % also cannot use 0 as the divisor |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
ZeroDivisionError — A Python runtime error raised when a number is divided by 0, or a remainder is taken with % 0. Guard against it with an if check or try/except.try:
avg = total / count
except ZeroDivisionError:if count != 0:
avg = total / countn = int(input("Divide by: "))
if n == 0:
print("Cannot divide by zero")divisor = 0
print(17 % divisor)try:
ratio = a / (a - b)
except ZeroDivisionError: