PCEP Control Flow, Loops, Lists and Logic Practice Question
A logistics analyst is writing a Python script that processes a list of shipment weights in kilograms. The analyst needs to display each weight one at a time and also know its position in the list, starting from 1 rather than 0. Which approach most directly accomplishes this?
⚠ Common exam trap
The trap here is assuming that list.index() returns the current loop position rather than the first matching element's index.
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
✓
Use for index, weight in enumerate(weights, start=1): and print index and weight.
The enumerate() function is designed to pair each element of an iterable with a counter. Supplying start=1 shifts the counter so the first shipment is numbered 1. Other approaches either produce 0-based indexes, mutate the list, or require manual offset adjustments that are easy to get wrong.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use for i in range(len(weights)): and print i and weights[i].
Why it's wrong here
This pattern does give access to both index and value, but the index begins at 0. To start numbering at 1, the analyst would have to remember to add 1 when printing, which is error-prone. The enumerate() function with start=1 expresses the intent directly and avoids off-by-one mistakes.
- ✗
Use for weight in weights: and print weights.index(weight).
Why it's wrong here
Calling weights.index(weight) inside the loop returns the first index of that value, not the current iteration position. If duplicate weights exist, the same index is reported repeatedly, and the displayed number would start at 0. It also performs a linear search on every iteration, making it inefficient and incorrect for tracking position reliably.
- ✗
Use while weights: and pop the first element each time, printing its value.
Why it's wrong here
A while loop that pops elements mutates the original list, destroying the data the analyst may still need. It also provides no index value unless a separate counter is maintained manually. While it can print each weight, it does not directly satisfy the requirement of knowing each item's 1-based position, and it has destructive side effects.
- ✓
Use for index, weight in enumerate(weights, start=1): and print index and weight.
Why this is correct
The enumerate() function yields pairs of an index and the corresponding element from the iterable. By passing start=1, the counter begins at one instead of the default zero, matching the analyst's requirement to number shipments from 1. This is the idiomatic and most direct way to obtain both position and value in a single loop without manual counter management.
Go deeper
Related to this question
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 →
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.