Courseiva

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

    Includes index 3, which the loop's range excludes via its stop value, and omits nothing else. It is tempting because listing every index feels complete, yet the range's upper bound is never produced by iteration.

  • ✓

    1 2 4 5

    Why this is correct

    Skipping 3 occurs because the loop body executes `continue` when the counter equals 3, bypassing the `print()` call for that iteration while the loop proceeds to 4 and 5. Values 1, 2, 4 and 5 are therefore printed, matching the required output exactly.

  • ✗

    1 2 3 4 5

    Why it's wrong here

    The loop's range or termination condition stops iteration before the value 5 is reached, so the output cannot contain all five numbers. Printing a full ascending sequence is tempting because range-based loops commonly produce it, but the exhibit's bounds or increment exclude the final value.

  • ✗

    2 4 5

    Why it's wrong here

    Omits index 0 and 3, which the loop still prints; the range includes both endpoints shown in the exhibit. It is tempting because skipping values looks like a filter, but no conditional exists in the code to exclude them.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 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 →

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.