PCEP ZeroDivisionError Practice Question
Exhibit
Refer to the exhibit.
def divide(a, b):
try:
return a / b
except ZeroDivisionError:
return float('inf')
except TypeError:
return None
result = divide(10, '5')
print(result)What is the output of the code?
⚠ Common exam trap
Candidates may assume the ZeroDivisionError is caught by the try-except block, but it is not; the exception goes unhandled, terminating the program.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
An unhandled ZeroDivisionError is raised.
The code divides by zero, which raises a ZeroDivisionError. The try-except block does not catch ZeroDivisionError (it catches a different exception or does not have an appropriate except clause), so the exception is unhandled, causing the program to terminate with a traceback. The output is not None; an unhandled exception is raised.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
None
Why it's wrong here
Incorrect. The function does not return None because an unhandled exception is raised before the function completes.
- ✗
inf
Why it's wrong here
Incorrect. Python does not return inf for division by zero; it raises ZeroDivisionError.
- ✗
2.0
Why it's wrong here
Incorrect. 2.0 is not the result because the division by zero raises an exception.
- ✓
An unhandled ZeroDivisionError is raised.
Why this is correct
Correct. Although the option states 'TypeError', the actual exception is ZeroDivisionError, but the key point is that an unhandled exception is raised, terminating the program.
Go deeper
Related to this question
About these practice questions
One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.