Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q13 of 15
Python - Exception Handling Fundamentals
What will be the output of the following code?
try:
    print('Start')
    x = 5 / 0
    print('End')
except ZeroDivisionError:
    print('Error caught')
print('Done')
AStart End Error caught Done
BError caught Done
CStart Done
DStart Error caught Done
Step-by-Step Solution
Solution:
  1. Step 1: Trace code inside try block

    It prints 'Start', then tries to divide 5 by 0, which raises ZeroDivisionError before printing 'End'.
  2. Step 2: Handle exception and continue

    The except block catches the error and prints 'Error caught'. After that, the program continues and prints 'Done'.
  3. Final Answer:

    Start Error caught Done -> Option D
  4. Quick Check:

    Exception stops try block, except runs = C [OK]
Quick Trick: Error stops try; except runs; code after try-except runs [OK]
Common Mistakes:
  • Assuming 'End' prints after error
  • Missing that except block runs
  • Thinking program stops after error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes