PCEP Control Flow, Loops, Lists and Logic Practice Question
A logistics coordinator stores shipment weights in a list `weights = [12, 18, 7, 25]`. She needs to find the average weight of all shipments. Which code snippet correctly computes and prints the average?
⚠ Common exam trap
Many candidates confuse the floor division operator `//` with true division `/`, leading to a truncated result instead of the exact average.
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
✓
print(sum(weights) / len(weights))
The average is calculated by dividing the sum of all elements by the number of elements. The built-in `sum()` and `len()` functions provide these values directly, and the `/` operator returns a float result. The other options either use incorrect functions or perform integer division, which loses the fractional part.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
print(total(weights) / len(weights))
Why it's wrong here
Python does not have a built-in function named `total()`. The correct function to sum an iterable is `sum()`. Using `total()` would raise a `NameError` at runtime. This option is a common distractor because the name sounds plausible but is not part of the Python standard library.
- ✗
print(mean(weights) / len(weights))
Why it's wrong here
The `mean()` function is not a built-in; it is provided by the `statistics` module and must be imported. Even if imported, dividing the mean by the length would double-divide by the count, producing an incorrect result. This option misuses a library function and performs an extra division.
- ✗
print(sum(weights) // len(weights))
Why it's wrong here
The `//` operator performs floor division, which discards any fractional part. For weights summing to 62 and a length of 4, this would produce 15 instead of 15.5, losing precision. While it avoids an error, it does not correctly compute the average when the division is not exact.
- ✓
print(sum(weights) / len(weights))
Why this is correct
This uses the built-in `sum()` to total all elements and divides by the count from `len()`, yielding the arithmetic mean. For the given list, the sum is 62 and the length is 4, so the average is 15.5. This is the standard, concise Python approach for averaging a list of numbers.
Go deeper
Related to this question
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 →
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.