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

PCEP Control Flow, Loops, Lists and Logic Practice Question

Exhibit

>>> my_list = [1, 2, 3, 4, 5]
>>> for i in range(len(my_list)):
...     if my_list[i] % 2 == 0:
...         my_list[i] = my_list[i] * 2
...     else:
...         my_list[i] = my_list[i] + 1
>>> print(my_list)

Refer to the exhibit. What is the output of the code?

⚠ Common exam trap

PCEP often tests the distinction between iterating over list elements directly (for x in lst) versus iterating over indices (for i in range(len(lst))), and the trap here is that candidates assume the loop doubles every element correctly without checking for off-by-one or assignment errors in the code.

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

[2, 4, 4, 8, 6]

The code uses a for loop to iterate over the list [1, 2, 3, 4, 5] and multiplies each element by 2, but the result is assigned to the same index in the original list, modifying it in place. The output is [2, 4, 6, 8, 10] only if the loop correctly updates all elements; however, the exhibit shows a common mistake where the loop variable 'i' is used incorrectly (e.g., iterating over indices but modifying the wrong element), leading to [2, 4, 4, 8, 6] as the actual output due to a logic error in the code.

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 →

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.