Question 44 of 498
PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
Exhibit
def exception_test():
try:
x = 1 / 0
except ZeroDivisionError:
print('A')
except:
print('B')
finally:
print('C')
print('D')
exception_test()Refer to the exhibit. What is the output?
⚠ Common exam trap
A common pitfall in Python PCEP exams is that dictionary iteration yields keys, but candidates may mistakenly think it yields values, or that the `in` operator checks keys rather than values, leading to incorrect filtering.
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
✓
A C D
The code defines a tuple containing numbers 1, 3, and 4 (e.g., `t = (1, 3, 4)`) and a dictionary `d = {'A': 1, 'B': 2, 'C': 3, 'D': 4}`. The `for` loop iterates over dictionary keys. The condition `if d[k] in t` checks if the associated value is in the tuple. Values 1, 3, and 4 are present, so keys A, C, and D are printed. Value 2 is absent, so B is not printed. The output is A, C, D each on a new line, matching option A.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
A C D
Why this is correct
Correct. First 'A', then 'C', then 'D'.
- ✗
B C D
Why it's wrong here
Incorrect. ZeroDivisionError is caught by the specific handler, not the generic one.
- ✗
A B C D
Why it's wrong here
Incorrect. Only one except clause executes.
- ✗
A C
Why it's wrong here
Incorrect. The print('D') after function call is also executed.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jul 4, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.