Courseiva
Control Flow, Loops, Lists and LogichardMultiple SelectObjective-mapped

PCEP Control Flow, Loops, Lists and Logic Practice Question

Which TWO of the following code snippets will print the numbers 0, 1, 2, 3, 4?

⚠ Common exam trap

Python Institute often tests the exclusive nature of the stop argument in `range()`, leading candidates to mistakenly think `range(5)` includes 5 or that `range(0,5)` includes 5, when in fact both produce 0 through 4.

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

for i in range(0,5): print(i)

`range(0,5)` generates the sequence 0, 1, 2, 3, 4. The `range()` function with two arguments (start, stop) produces numbers from start inclusive up to, but not including, stop. Therefore, iterating with `for i in range(0,5): print(i)` prints exactly 0 through 4.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • for i in range(0,5): print(i)

    Why this is correct

    Prints 0..4.

  • for i in range(5+1): print(i)

    Why it's wrong here

    Prints 0..5.

  • for i in range(5): print(i)

    Why this is correct

    Prints 0..4.

  • for i in range(0,5,2): print(i)

    Why it's wrong here

    Prints 0,2,4 only.

  • for i in range(1,6): print(i)

    Why it's wrong here

    Prints 1..5.

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 →

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.