Conditions & Loops · Question 3 · Easy

A loop accumulates the numbers from range(1, 6). What total is printed?

total = 0
for n in range(1, 6):
    total += n
print(total)
  1. 10
  2. 15
  3. 21
  4. 6
Answer and explanation

Answer: B. 15

Explanation: range(1, 6) gives 1, 2, 3, 4, 5; the stop value 6 is excluded. Their sum is 15.

Previous: A for loop prints the numbers produced by range(3) on one line. What is the… · Next: Which statement skips the rest of the current iteration and moves on to the…

Practise conditions & loops

Try a fresh set of conditions & loops questions with an explanation after every answer, free and without signing up: Conditions & Loops practice. Or sit a full placement mock test.

More conditions & loops questions

More python practice

Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge