What is the output of the following Python code snippet?
try:
1 / 0
except ZeroDivisionError:
print('Cannot divide by zero')
-
A
0
-
B
inf
-
C
Cannot divide by zero
Correct answer
-
D
Error
Correct answer
C. Cannot divide by zero
Explanation
Dividing by zero raises ZeroDivisionError, which the except block handles.
Doubts & discussion
Not sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ