Question 37 of 498
PCEP Control Flow, Loops, Lists and Logic Practice Question
A junior developer writes a Python script to sum all numbers greater than 10 from a list. The code is:
numbers = [5, 12, 8, 15, 3] total = 0
for num in numbers:
if num > 10:total = total + 1
print(total)
The output is 2, but the expected sum is 27 (12+15). Which change will produce the correct output?
⚠ Common exam trap
Many candidates confuse counting with summing — they see `total = total + 1` and think it's accumulating values, but it actually increments by a constant, not by the variable `num`.
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
✓
Change `total = total + 1` to `total += num`
The original code increments `total` by 1 for each qualifying number, counting them instead of summing their values. Changing `total = total + 1` to `total += num` adds the actual number to the accumulator, producing the correct sum of 12 + 15 = 27.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Change `total = 0` to `total = []`
Why it's wrong here
total becomes a list; adding an integer to a list appends, but printing total would output a list.
- ✓
Change `total = total + 1` to `total += num`
Why this is correct
Adds the number value instead of 1, giving the correct sum.
- ✗
Change `if num > 10:` to `if num >= 10:`
Why it's wrong here
This would include 10 if present, but the sum would still be 27 if 10 were not there; however, the problem is that the code counts instead of sums.
- ✗
Change `for num in numbers:` to `for num in range(numbers):`
Why it's wrong here
range() expects an integer, not a list; this causes a TypeError.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 25, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.