Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A programmer wants to create a list of even numbers from 0 to 10 inclusive. Which list comprehension is correct?

⚠ Common exam trap

Python Institute often tests the distinction between `range(0,11)` and `range(0,10)` to catch candidates who forget that the stop value is exclusive, and the use of truthy/falsy values in conditions (e.g., `if x%2` instead of `if x%2==0`) to confuse even vs. odd selection.

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

✓

[x for x in range(0,11) if x%2==0]

It uses `range(0,11)` to generate numbers from 0 to 10 inclusive, and the condition `if x%2==0` selects only even numbers (where the remainder when divided by 2 is 0). This matches the requirement exactly.

Answer analysis

Option-by-option breakdown

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

  • ✓

    [x for x in range(0,11) if x%2==0]

    Why this is correct

    The comprehension iterates over `range(0,11)`, whose stop value is exclusive, so it yields 0 through 10 inclusive as the stem requires. The filter `x%2==0` then retains only even values, producing `[0,2,4,6,8,10]` in a single expression without needing an explicit append loop.

  • ✗

    [x for x in range(0,10) if x%2==0]

    Why it's wrong here

    range(0,10) stops at 9, so 10 is excluded and the result is 0, 2, 4, 6, 8 rather than including 10. It is tempting because the modulo condition is correct and range's exclusive upper bound is easy to overlook; range(0,11) would include 10.

  • ✗

    [x for x in range(0,11) if x%2]

    Why it's wrong here

    Non-zero values are truthy, gives odd numbers.

  • ✗

    [x for x in range(0,11) if x%2==1]

    Why it's wrong here

    Gives odd numbers.

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.