Bird
0
0

Identify the issue in this code snippet:

medium📝 Debug Q6 of 15
Python - Advanced Exception Handling
Identify the issue in this code snippet:
def calculate(a, b):
    if b == 0:
        raise ZeroDivisionError('division by zero')
    return a / b

print(calculate(5, 0))
ANo issue; code will raise ZeroDivisionError correctly
BZeroDivisionError cannot be raised with a message
CThe raise statement should be inside a try block
DThe function should return None instead of raising
Step-by-Step Solution
Solution:
  1. Step 1: Analyze raise usage

    The code raises a built-in exception with a message correctly.
  2. Step 2: Check syntax and logic

    Raising ZeroDivisionError with a string is valid syntax.
  3. Final Answer:

    No issue; code will raise ZeroDivisionError correctly -> Option A
  4. Quick Check:

    Raising built-in exceptions with messages is valid [OK]
Quick Trick: raise built-in exceptions with message is valid syntax [OK]
Common Mistakes:
  • Thinking raise must be inside try block
  • Believing built-in exceptions cannot have messages
  • Expecting function to handle error instead of raising

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes