Courseiva

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

    Checking counter != 0 stops at zero, so the value 1 is never printed and the countdown ends one step early. This condition fits loops that must terminate on a sentinel value, not a fixed inclusive range.

  • ✗

    while counter >= 0:

    Why it's wrong here

    Allowing counter >= 0 lets the loop run one extra iteration, printing 0 after 1 and only then stopping. That boundary suits sequences ending at zero, whereas a countdown finishing at 1 must exclude zero.

  • ✗

    while counter < 10:

    Why it's wrong here

    Testing counter < 10 fails immediately at the starting value of 10, so the body never executes and no countdown occurs. Such a condition suits counting upwards from zero, not decrementing from ten down to one.

  • ✓

    while counter > 0:

    Why this is correct

    With counter starting at 10 and decrementing, the loop must continue while counter remains above zero, so counter > 0 keeps iterations running for values 10 down to 1 and terminates once counter reaches 0, preventing an extra countdown iteration.

About these practice questions

One of 482 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 →

How Courseiva writes practice questions · Editorial policy

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.