Conditions & Loops · Question 12 · Medium

The inner loop's range depends on the outer loop variable. How many times does the counter increase?

count = 0
for i in range(3):
    for j in range(i):
        count += 1
print(count)
  1. 3
  2. 6
  3. 9
  4. 2
Answer and explanation

Answer: A. 3

Explanation: The inner loop runs i times: 0 times when i is 0, once when i is 1 and twice when i is 2. That is 0 + 1 + 2 = 3 increments.

Previous: zip() pairs two lists of unequal length inside a loop. What total is printed? · Next: A helper function prints its argument each time it is called inside and / or…

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