Courseiva

PCEP Control Flow, Loops, Lists and Logic Practice Question

A developer is reviewing loop constructs that iterate over the list scores = [10, 20, 30]. Which two statements about iterating this list are true? (Choose two.)

⚠ Common exam trap

The trap here is assuming a plain for loop over a list provides indices, when it actually yields element values.

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 s in scores: accesses each element value directly, so s takes the values 10, 20, and 30 in order.

Python lets you iterate a list either by value, where the loop variable receives each element, or by index, where a range over the list's length supplies positions usable with subscripting. Direct value iteration is simplest for reading data, while index iteration is needed when positions matter. Appending during iteration is unreliable, and an empty list produces no iterations.

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 s in scores: assigns s to each index position, so s holds 0, 1, and 2 during iteration.

    Why it's wrong here

    Direct iteration over a list yields the elements, not the indices. The variable s receives 10, 20, and 30, not 0, 1, and 2. Confusing values with positions is a common error; when indices are required, a range-based loop or enumerate must be used instead of plain iteration.

  • ✓

    for s in scores: accesses each element value directly, so s takes the values 10, 20, and 30 in order.

    Why this is correct

    Iterating a list directly yields its elements, so the loop variable receives 10, then 20, then 30. This is the most direct way to read values when the positions are not needed. The list itself is not modified, and the order follows the list's internal sequence, which here matches the order in which the values were written.

  • ✓

    for i in range(len(scores)): gives i the values 0, 1, and 2, which can be used to index scores.

    Why this is correct

    range(len(scores)) produces 0, 1, and 2 because the list has three elements and indexing starts at zero. Using i as an index, scores[i] retrieves 10, 20, and 30. This pattern is useful when the position of each element is needed alongside its value, such as when updating elements in place.

  • ✗

    Modifying scores by appending a new element during a for loop over scores reliably processes the appended element in the same loop.

    Why it's wrong here

    Mutating a list while iterating it is risky and does not reliably visit appended elements. The iterator tracks position internally, and changes to the list's size can cause elements to be skipped or repeated. The safe approach is to iterate over a copy or build a separate result list rather than altering the source mid-loop.

  • ✗

    A for loop over scores always executes at least once, even when the list is empty.

    Why it's wrong here

    A for loop over an empty list executes zero times because there is nothing to iterate. The loop body runs once per element, so no elements means no iterations. Only a while loop with an initially true condition, or a do-while style construct that Python lacks, would guarantee at least one execution.

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.