PCEP Control Flow, Loops, Lists and Logic Practice Question
A developer needs to write a loop that prints all even numbers from a list. They attempt: for num in numbers: if num % 2 == 0: print(num). However, they want a more efficient approach using list comprehension. Which alternative achieves the same result?
⚠ Common exam trap
Python Institute often tests the distinction between generating a list of filtered values versus printing them individually, and the trap here is that candidates may think option A is correct because it uses list comprehension, but they overlook that it prints the entire list as a single output, not each element separately.
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 even in [num for num in numbers if num % 2 == 0]: print(even)
It uses a list comprehension to generate a list of even numbers, then iterates over that list with a for loop, printing each even number. This achieves the same result as the original loop but with the efficiency of list comprehension for filtering, while still printing each number individually.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
print([num for num in numbers if num % 2 == 0])
Why it's wrong here
This prints the entire list of evens at once, not each number individually.
- ✗
for num in numbers: print(num if num % 2 == 0 else None)
Why it's wrong here
This prints None for odd numbers, not desired.
- ✓
for even in [num for num in numbers if num % 2 == 0]: print(even)
Why this is correct
Correct: list comprehension filters even numbers, then loop prints each.
- ✗
print([num % 2 == 0 for num in numbers])
Why it's wrong here
This creates a list of booleans, not printing the numbers.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 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 →
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.