Bird
Raised Fist0

What will this code print?

medium📝 Predict Output Q5 of Q15
Python - Advanced Exception Handling
What will this code print?
try:
    x = 5 / 0
except ZeroDivisionError:
    print("Caught ZeroDivisionError")
else:
    print("No Exception")
AZeroDivisionError
BNo Exception
CCaught ZeroDivisionError
D5
Step-by-Step Solution
Solution:
  1. Step 1: Identify exception in try block

    Division by zero raises ZeroDivisionError, so except block runs.
  2. Step 2: Check else block execution

    Else block runs only if no exception, so it is skipped here.
  3. Final Answer:

    Caught ZeroDivisionError -> Option C
  4. Quick Check:

    Exception triggers except, else skipped = D [OK]
Quick Trick: Else skips if except runs due to error [OK]
Common Mistakes:
MISTAKES
  • Expecting else to run despite exception
  • Confusing exception message with print output
  • Ignoring exception type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes