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

PCEP Control Flow, Loops, Lists and Logic Practice Question

A program needs to print the index and value of each item in a list named 'items'. Which code snippet correctly does this?

⚠ Common exam trap

Python Institute often tests the misconception that `items.index(item)` is a reliable way to get the current index, but it fails with duplicate values and is computationally expensive, leading candidates to incorrectly select option D.

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

Both A and C are correct

Both Option A and Option C are valid code snippets that correctly print the index and value of each item in the list. Option A uses the clean, Pythonic enumerate() function. Option C uses range(len(items)) to iterate by index. Since both are correct, the best answer is B, which correctly identifies that both A and C are correct. Option D is incorrect because items.index(item) can fail with duplicate values and is inefficient.

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 i, item in enumerate(items): print(i, item)

    Why it's wrong here

    Correct. `enumerate(items)` yields index-value pairs, which are printed correctly.

  • Both A and C are correct

    Why this is correct

    Incorrect. This option is a meta-statement, not a code snippet. The question asks for the correct code snippet, so it does not qualify.

  • for i in range(len(items)): print(i, items[i])

    Why it's wrong here

    Correct. Iterating over indices and accessing `items[i]` gives the index and value, achieving the goal.

  • for item in items: print(items.index(item), item)

    Why it's wrong here

    Incorrect. `items.index(item)` returns the first occurrence index, which is unreliable with duplicates and inefficient, so this does not correctly print index and value for all items.

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.