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

PCEP Control Flow, Loops, Lists and Logic Practice Question

A developer writes a loop to sum numbers from 1 to 10. The code outputs 55, but the expected sum is 55. However, the loop uses a range that includes 0. Which range should be used to achieve the correct sum?

⚠ Common exam trap

Python Institute often tests the exclusive nature of range()'s stop parameter, tricking candidates into thinking range(1,10) includes 10 or that range(0,11) is equivalent to range(1,11) when the sum is unchanged by zero.

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

range(1,11)

(range(1,11)) is correct because range(start, stop) generates numbers from start inclusive to stop exclusive. To sum numbers 1 through 10, the range must start at 1 and end at 11 (so 10 is included). The loop that used range(0,11) included 0, but since adding 0 does not change the sum, the output was still 55 — however, the question asks for the range that achieves the correct sum without including unnecessary values.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • range(0,11)

    Why it's wrong here

    Includes 0, which is unnecessary but still sums to 55; however the question says the loop includes 0 and that's not desired.

  • range(1,11)

    Why this is correct

    Correctly generates 1..10

  • range(0,101)

    Why it's wrong here

    Generates 0..100, sum 5050

  • range(1,10)

    Why it's wrong here

    Generates 1..9, sum 45

About these practice questions

This PCEP question is part of Courseiva's 498-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.