PCEP range() Practice Question
Exhibit
>>> x = 0 >>> while x < 5: ... x += 1 ... if x == 3: ... continue ... print(x, end=' ') 1 2 4 5
Refer to the exhibit. What is the output of the code?
⚠ Common exam trap
Candidates often confuse range(1,6) with range(5) or miss that continue skips only the current iteration, not the whole loop. They may also forget that range start is inclusive and end is exclusive.
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 4 5
The code uses a for loop with range(1,6) to iterate over numbers 1 through 5. Inside the loop, an if statement checks if the current number equals 3; if true, the continue statement skips the print(i) for that iteration. Thus, when i is 3, the print is skipped, so the output is '1 2 4 5'. Option B is correct because it matches this output.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
0 1 2 4 5
Why it's wrong here
Incorrect. This output would occur if the code used range(5) (0-4) with continue on i==3, but the actual code starts at 1.
- ✓
1 2 4 5
Why this is correct
Correct. The loop iterates from 1 to 5, skipping 3 due to continue, resulting in 1,2,4,5.
- ✗
1 2 3 4 5
Why it's wrong here
Incorrect. This output would occur if there was no continue and the loop printed all numbers from 1 to 5.
- ✗
2 4 5
Why it's wrong here
Incorrect. This output would occur if the loop started at 2 and skipped 3, but the actual range includes 1.
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.