Bird
0
0

Find the error in this code and choose the correct fix:

medium📝 Debug Q14 of 15
Python - Exception Handling Fundamentals
Find the error in this code and choose the correct fix:
try:
    print(10 / 0)
except ZeroDivisionError, e:
    print('Error:', e)
AUse except ZeroDivisionError(e):
BChange except line to: except ZeroDivisionError as e:
CChange print to print('Error') only
DRemove the except block completely
Step-by-Step Solution
Solution:
  1. Step 1: Identify the syntax error in except clause

    Python 3 requires 'as' to assign exception to a variable, not a comma.
  2. Step 2: Correct the except syntax

    Replace except ZeroDivisionError, e: with except ZeroDivisionError as e:.
  3. Final Answer:

    Change except line to: except ZeroDivisionError as e: -> Option B
  4. Quick Check:

    Use 'as' to assign exception variable [OK]
Quick Trick: Use 'except Exception as e:' syntax in Python 3 [OK]
Common Mistakes:
  • Using comma instead of 'as' in except
  • Removing except block causing crash
  • Wrong parentheses in except clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes