Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
Python - Exception Handling Fundamentals
What will be the output of this code?
try:
    x = 5 / 0
except ZeroDivisionError:
    print('Cannot divide by zero')
ANo output
B5
CZeroDivisionError
DCannot divide by zero
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the code inside try block

    The code tries to divide 5 by 0, which causes a ZeroDivisionError.
  2. Step 2: Check the except block

    The except block catches ZeroDivisionError and prints 'Cannot divide by zero'.
  3. Final Answer:

    Cannot divide by zero -> Option D
  4. Quick Check:

    ZeroDivisionError caught prints message [OK]
Quick Trick: Division by zero triggers ZeroDivisionError [OK]
Common Mistakes:
  • Expecting program to crash without output
  • Confusing error name with printed message
  • Ignoring except block handling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes