PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
A developer writes a function `def process(data):` that uses a try-except-else-finally block. The try block reads from a file, the except block handles IOError, the else block processes the data, and the finally block closes the file. If no exception occurs, which blocks execute and in what order?
⚠ Common exam trap
The trap here is assuming that the else block runs only if an exception occurs, or that the except block always runs, but the else block is specifically for the no-exception path.
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
✓
try, else, finally
In a try-except-else-finally structure, the try block runs first. If it completes without raising an exception, the else block executes. The finally block always executes, regardless of whether an exception occurred. The except block only runs if an exception is raised. Therefore, with no exception, the order is try, else, finally.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
try, except, finally
Why it's wrong here
The except block only executes if an exception is raised in the try block. Since the scenario states no exception occurs, the except block is skipped. The finally block still executes, but the except block does not. This option incorrectly includes the except block.
- ✗
try, else, except, finally
Why it's wrong here
The except block does not execute if no exception occurs. Including it in the sequence is wrong. The correct order when no exception occurs is try, else, finally. The except block is only for handling exceptions, so it is not part of the normal flow.
- ✓
try, else, finally
Why this is correct
When no exception occurs in the try block, the else block executes after the try block completes successfully. The finally block always executes, regardless of exceptions, so it runs last. The except block is skipped because no exception was raised. Thus the order is try, else, finally.
- ✗
try, finally
Why it's wrong here
The else block executes when the try block completes without raising an exception. It is not skipped. The finally block also executes, but the else block runs before finally. This option omits the else block, which is incorrect for the no-exception case.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.