PCAP Exceptions and File I/O Practice Question
What is the output of the following code?
try:
print(1/0)
except:
print('err')finally:
print('fin')⚠ Common exam trap
Python Institute often tests the order of execution in try/except/finally blocks, specifically that the except block runs before the finally block when an exception is caught, and that the finally block always executes even if no exception occurs.
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
✓
err fin
When a division by zero occurs, Python raises a ZeroDivisionError, which is caught by the bare except clause, printing 'err'. The finally clause always executes after the except block, printing 'fin'. Thus the output is 'err' followed by 'fin'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
fin err
Why it's wrong here
This output reverses the actual order of execution. When an exception is raised in the try block, control jumps immediately to the matching except clause, which prints "err"; only after that exception handler completes does the interpreter execute the finally block, which prints "fin". Therefore the correct sequence is "err fin", making "fin err" impossible.
- ✗
fin
Why it's wrong here
This output omits the except block's output entirely. Because the try block raises an exception that is caught by the matching except clause, that handler is executed and produces "err" before the finally block runs. The finally block always executes afterward, adding "fin", so the complete output must contain both strings, not just one.
- ✓
err fin
Why this is correct
After an exception is raised in the try block, Python finds the matching except clause and executes its body, printing "err". The finally clause then executes unconditionally as part of exception handling, printing "fin" after the except handler completes. Thus the full and correct output is "err fin".
- ✗
err
Why it's wrong here
This output ignores the finally clause, which is guaranteed to execute regardless of whether an exception was handled. Since a finally block runs after the except handler finishes, "fin" is printed immediately after "err". Omitting "fin" would only be possible if the process terminated abnormally, such as via os._exit() inside the except block, which is not the case here.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP 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 PCAP exam.