PCEP Control Flow, Loops, Lists and Logic Practice Question
A developer writes a while loop to count down from 10 to 1 and then stop. Which condition should be used?
⚠ Common exam trap
Python Institute often tests the off-by-one error where candidates choose `>= 0` thinking they need to include 0, but the requirement to stop at 1 means the loop must not execute when counter is 0.
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
✓
while counter > 0:
The while loop must continue as long as the counter is greater than 0, counting down from 10 to 1. When counter becomes 0, the condition `counter > 0` evaluates to False, and the loop terminates, stopping exactly at 1.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
while counter != 0:
Why it's wrong here
This works but is less explicit; also could be infinite if counter never hits 0 exactly due to step? In this case fine, but B is clearer.
- ✗
while counter >= 0:
Why it's wrong here
This includes 0, so it counts from 10 down to 0, not stopping at 1.
- ✗
while counter < 10:
Why it's wrong here
This would not decrement correctly; it would require an increment condition, not appropriate for countdown.
- ✓
while counter > 0:
Why this is correct
Correct: runs while counter is positive; stops when counter becomes 0.
Go deeper
Related to this question
About these practice questions
One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.