Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Python - Exception Handling Fundamentals
What will be the output of this code?
try:
    print(10 / 2)
except Exception:
    print('Error occurred')
else:
    print('No errors')
AError occurred
B5.0
C5.0 No errors
DNo errors
Step-by-Step Solution
Solution:
  1. Step 1: Analyze try block

    Division 10 / 2 equals 5.0 and does not raise an exception.
  2. Step 2: Understand else block

    Since no exception occurs, the else block runs and prints 'No errors'.
  3. Final Answer:

    5.0 No errors -> Option C
  4. Quick Check:

    Else runs only if no exception [OK]
Quick Trick: Else block runs only if try succeeds without exceptions [OK]
Common Mistakes:
  • Expecting else to run after exception
  • Missing that print(10 / 2) outputs 5.0
  • Confusing except and else blocks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes