Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A programmer is debugging a Python script that uses a while loop to process a list of numbers. The code is:

numbers = [1, 2, 3, 4, 5] i = 0

while i < len(numbers):
    if numbers[i] % 2 == 0:
        print(numbers[i])

i += 1

What is the output of this code?

⚠ Common exam trap

The trap here is misreading the modulo condition and thinking it prints odd numbers, or overlooking the increment that prevents an infinite loop.

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

✓

2 4

The while loop iterates through the list by index, checking each element for evenness using the modulo operator. When an even number is found, it is printed. The loop correctly increments the index, so it terminates after processing all elements. The even numbers in the list are 2 and 4, so they are printed on separate lines.

Answer analysis

Option-by-option breakdown

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

  • ✗

    2 4 6

    Why it's wrong here

    The list only contains numbers up to 5, so 6 is not in the list and cannot be printed. The loop iterates over the given list, and the condition only checks elements present. There is no 6, so it is not output. This option mistakenly assumes the loop generates numbers beyond the list.

  • ✗

    An infinite loop occurs because i is not incremented.

    Why it's wrong here

    The variable i is incremented by 1 at the end of each iteration (i += 1). This ensures the loop progresses and terminates when i reaches len(numbers), which is 5. There is no infinite loop. This option incorrectly claims that the increment is missing, but it is present in the code.

  • ✗

    1 3 5

    Why it's wrong here

    This would be the output if the condition were numbers[i] % 2 != 0, which checks for odd numbers. The code checks for even numbers, so it prints evens, not odds. The numbers 1, 3, and 5 are odd and do not satisfy the condition. Therefore, they are not printed. This option confuses the modulo condition.

  • ✓

    2 4

    Why this is correct

    The loop iterates over the list using index i from 0 to 4. The condition checks if the current number is even (numbers[i] % 2 == 0). For 1, it's odd (no print). For 2, it's even (print 2). For 3, odd. For 4, even (print 4). For 5, odd. So the output is 2 and 4 on separate lines. The loop increments i correctly, avoiding an infinite loop.

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 and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Python Institute exam blueprint

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.