Bird
0
0

Find the problem in this code:

medium📝 Debug Q7 of 15
Python - Exception Handling Fundamentals
Find the problem in this code:
try:
    print('Hello')
except Exception as e:
print(e)
APrint statement should be outside except
BIndentation error in except block
CMissing exception type
DTry block cannot have print statements
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation rules

    Code inside except block must be indented. Here, print(e) is not indented.
  2. Step 2: Verify other parts

    Exception type is present, print inside except is valid, try block can have print.
  3. Final Answer:

    Indentation error in except block -> Option B
  4. Quick Check:

    Indent code inside except block properly [OK]
Quick Trick: Indent all code inside except block [OK]
Common Mistakes:
  • Not indenting except block code
  • Removing exception type
  • Misplacing print statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes