143k views
0 votes
Select the appropriate error to be put in this except clause: for i in range(‐3,7): try: print(7/i) except ______ __: print.

User Aslingga
by
8.4k points

1 Answer

1 vote

Final answer:

The appropriate error to be put in the except clause is ZeroDivisionError. If the variable 'i' takes a value of 0, the except block will execute and print a custom message.

Step-by-step explanation:

The appropriate error to be put in the except clause is ZeroDivisionError. This error occurs when a division or modulo operation is performed with a divisor of zero. In the given code, it would be raised if the variable 'i' takes a value of 0, resulting in a division by zero. Here's the corrected code:

for i in range(-3, 7):
try:
print(7 / i)
except ZeroDivisionError:
print('Cannot divide by zero')
In this updated code, if 'i' is 0, the

except

block will execute and print a custom message.

User Charlie Wu
by
8.2k points