Bird
Raised Fist0

What is the output of this code?

medium📝 Predict Output Q4 of Q15
Python - Advanced Exception Handling
What is the output of this code?
try:
    print("Hello")
except:
    print("Error")
else:
    print("No Error")
AHello\nNo Error
BError\nNo Error
CHello
DNo Error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze try block output

    The try block prints "Hello" and does not raise an exception.
  2. Step 2: Check else block execution

    Since no exception occurred, the else block runs and prints "No Error".
  3. Final Answer:

    Hello\nNo Error -> Option A
  4. Quick Check:

    Try success triggers else = C [OK]
Quick Trick: Else runs only if try succeeds, prints after try [OK]
Common Mistakes:
MISTAKES
  • Assuming except runs without error
  • Thinking else runs before try
  • Missing newline in output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes