Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A developer needs to iterate over a list named `colors` and print each color on a separate line. Which code snippet correctly accomplishes this?

⚠ Common exam trap

The trap here is forgetting the colon at the end of the for statement or misindenting the loop body, which are common syntax errors for beginners.

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 color in colors: print(color)

The correct way to iterate over a list and print each element is to use a for loop with proper indentation and a colon at the end of the loop header. The loop variable takes each element from the list in turn, and the indented block executes for each element. This pattern is fundamental in Python for processing sequences.

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 (color in colors): print(color)

    Why it's wrong here

    Parentheses around the loop variable and iterable are not valid syntax in Python's for loop. The correct form is `for variable in iterable:`. Adding parentheses will cause a `SyntaxError` because Python expects a colon immediately after the iterable.

  • ✗

    for color in colors: print(color)

    Why it's wrong here

    In Python, indentation is mandatory to define the block of code that belongs to the loop. Without indentation, the `print` statement is not considered part of the loop body, and the code will raise an `IndentationError`. The indentation must be consistent.

  • ✗

    for color in colors print(color)

    Why it's wrong here

    A colon (:) is required at the end of the `for` statement to indicate the start of the loop body. Omitting it results in a `SyntaxError`. The correct syntax includes a colon after the iterable expression.

  • ✓

    for color in colors: print(color)

    Why this is correct

    This is the correct syntax for a for loop in Python. The loop variable `color` takes each value from the list `colors` one at a time, and `print(color)` outputs it. This is the most straightforward and idiomatic way to iterate over a list and perform an action for each element.

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.