Conditions & Loops · Question 2 · Easy

A for loop prints the numbers produced by range(3) on one line. What is the output?

for i in range(3):
    print(i, end=" ")
  1. 1 2 3
  2. 0 1 2
  3. 0 1 2 3
  4. 1 2
Answer and explanation

Answer: B. 0 1 2

Explanation: range(3) starts at 0 and stops before 3, so it gives 0, 1 and 2.

Previous: An if-elif ladder assigns a grade for 68 marks. What does it print? · Next: A loop accumulates the numbers from range(1, 6). What total is printed?

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