PCEP Control Flow, Loops, Lists and Logic Practice Question
Exhibit
Refer to the exhibit.
nums = [1, 2, 3, 4, 5]
for n in nums:
if n == 3:
break
print(n)
else:
print('Done')What is the output of the code?
⚠ Common exam trap
Python Institute often tests the distinction between `break` and `continue`, and the trap here is that candidates forget that `break` exits the loop entirely, not just the current iteration, leading them to incorrectly include the value that triggered the break in the output.
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
✓
1 2
The code uses a `for` loop with `range(1, 4)` which generates the sequence 1, 2, 3. Inside the loop, `if i == 3: break` causes the loop to terminate when `i` equals 3, so the loop only prints 1 and 2 before breaking. There is no additional print statement after the loop, so the output is just `1` and `2` on separate lines.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
1 2
Why this is correct
Correct: prints 1, then 2, then loop ends.
- ✗
1 2 3 Done
Why it's wrong here
Neither 3 nor Done are printed.
- ✗
1 2 Done
Why it's wrong here
Else clause does not execute because break occurred.
- ✗
1 2 3
Why it's wrong here
break occurs before printing 3.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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 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.