Bird
Raised Fist0

Find the error in this code snippet:

medium📝 Debug Q14 of Q15
Python - Exception Handling Fundamentals
Find the error in this code snippet:
try:
    print(10 / 0)
except Exception
    print("Caught error")
AMissing colon after except Exception
BDivision by zero is not caught by Exception
Cprint statement syntax is wrong
Dtry block should have an else clause
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of except block

    The except line is missing a colon at the end, which is required in Python syntax.
  2. Step 2: Confirm other parts are correct

    Division by zero raises ZeroDivisionError, subclass of Exception, so it is caught. The print statement syntax is correct. Else clause is optional.
  3. Final Answer:

    Missing colon after except Exception -> Option A
  4. Quick Check:

    except line must end with colon : [OK]
Quick Trick: Always put colon after except Exception: [OK]
Common Mistakes:
MISTAKES
  • Forgetting colon after except
  • Thinking division by zero is uncaught
  • Believing else clause is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes