Courseiva
Control Flow, Loops, Lists and LogiceasyMultiple ChoiceObjective-mapped

PCEP List indexing Practice Question

Exhibit

numbers = [1, 2, 3, 4, 5]
for i in range(len(numbers)):
    if numbers[i] % 2 == 0:
        numbers[i] = numbers[i] * 2
print(numbers)

Refer to the exhibit. What is the output?

⚠ Common exam trap

Candidates often mistakenly apply the operation to every element instead of only odd indices, or they confuse the operation (multiply vs add) based on the element's parity, leading them to choose option B ([2,4,6,8,10]) or D ([1,2,3,4,5]).

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

[1, 4, 3, 8, 5]

The code iterates over the list `[1, 2, 3, 4, 5]` using indices. It only modifies elements at odd indices (index 1 and 3). For those elements, if the value is even, it multiplies by 2; if odd, it adds 2. At index 1, value 2 (even) becomes 4; at index 3, value 4 (even) becomes 8. Elements at even indices (0, 2, 4) remain unchanged: 1, 3, 5. Thus the final list is `[1, 4, 3, 8, 5]`.

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, 5, 7, 9, 5]

    Why it's wrong here

    Incorrect. This output would correspond to a different logic, such as multiplying every odd number by 2 and adding 2 to every even number, but applied to all elements or a different condition.

  • [2, 4, 6, 8, 10]

    Why it's wrong here

    Incorrect. This output results from applying the operation to every element (e.g., odd→*2, even→+2) or a similar global rule, ignoring the index-based restriction.

  • [1, 4, 3, 8, 5]

    Why this is correct

    Correct. Only elements at odd indices are modified as described, yielding [1,4,3,8,5].

  • [1, 2, 3, 4, 5]

    Why it's wrong here

    Incorrect. This is the original list; it would only remain unchanged if no modifications were made, which is not the case here.

About these practice questions

This PCEP question is part of Courseiva's 498-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.