Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A developer is writing a Python script that must iterate over the characters of the string stored in variable `word` and print each character on its own line, without using index numbers. Which of the following loops accomplishes this?

⚠ Common exam trap

The trap here is assuming a `for` loop over a string needs `range()` and indexing, when the string itself is already directly iterable.

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 ch in word: print(ch)

A Python `for` loop iterates directly over any iterable object, and strings are iterables that produce their characters one at a time. Binding each character to a loop variable and printing it yields exactly one character per line in the original order. The remaining constructs either iterate over numeric indexes, never advance the loop variable, or split the string into words rather than characters.

Answer analysis

Option-by-option breakdown

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

  • ✗

    while word: print(word)

    Why it's wrong here

    This is wrong because the loop condition tests the whole string and never changes it. Since `word` stays truthy for the entire run, the loop prints the complete string over and over forever, an infinite loop. Even if it terminated, it prints the entire word each time rather than one character per line as required.

  • ✗

    for ch in word.split(): print(ch)

    Why it's wrong here

    The `split()` method divides a string into a list of substrings at whitespace, so for a single word it returns a one-element list containing the whole word. The loop therefore prints the entire word once instead of each character separately. It only appears to work for multi-word strings, and even then it prints words, not characters.

  • ✓

    for ch in word: print(ch)

    Why this is correct

    This is correct because a Python `for` loop directly iterates over any iterable, and a string is an iterable that yields one character per iteration. Each pass binds `ch` to the next character and prints it, producing one character per line in order. No index counter or range is needed, which is the idiomatic and simplest solution for this scenario.

  • ✗

    for ch in range(len(word)): print(ch)

    Why it's wrong here

    This fails because `range(len(word))` yields integers from 0 up to the length minus one, not the characters themselves. The loop would print 0, 1, 2, and so on, so the actual letters never appear. To get characters this way you would have to index the string with `word[ch]`, which the snippet does not do.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 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 →

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.