Python - Exception Handling FundamentalsWhich of the following is the correct syntax to catch a ZeroDivisionError in Python?Atry:\n x = 1 / 0\ncatch ZeroDivisionError:\n print('Cannot divide by zero')Btry:\n x = 1 / 0\nexcept error.ZeroDivisionError:\n print('Cannot divide by zero')Ctry:\n x = 1 / 0\nexcept ZeroDivisionError:\n print('Cannot divide by zero')Dtry:\n x = 1 / 0\nexcept ZeroDivision:\n print('Cannot divide by zero')Check Answer
Step-by-Step SolutionSolution:Step 1: Recall Python exception syntaxPython uses try-except blocks with 'except ExceptionType:' syntax.Step 2: Identify correct exception name and syntaxZeroDivisionError is the correct exception name; 'except ZeroDivisionError:' is valid.Final Answer:try-except with except ZeroDivisionError: -> Option CQuick Check:Correct try-except syntax = try:\n x = 1 / 0\nexcept ZeroDivisionError:\n print('Cannot divide by zero') [OK]Quick Trick: Use 'except ExceptionType:' to catch exceptions [OK]Common Mistakes:MISTAKESUsing 'catch' instead of 'except'Wrong exception nameWrong module prefix
Master "Exception Handling Fundamentals" in Python9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Python Quizzes Context Managers - Automatic resource cleanup - Quiz 1easy Encapsulation and Data Protection - Name mangling - Quiz 14medium Encapsulation and Data Protection - Private attributes - Quiz 4medium Exception Handling Fundamentals - Why exceptions occur - Quiz 3easy Exception Handling Fundamentals - Try–except execution flow - Quiz 7medium File Handling Fundamentals - Why file handling is required - Quiz 9hard File Reading and Writing Strategies - Reading files line by line - Quiz 9hard Multiple Inheritance and Method Resolution - Best practices for multiple inheritance - Quiz 6medium Standard Library Usage - Random data generation - Quiz 7medium Structured Data Files - Serializing and deserializing JSON - Quiz 9hard