Conditions & Loops · Question 11 · Medium

zip() pairs two lists of unequal length inside a loop. What total is printed?

total = 0
for a, b in zip([1, 2, 3], [4, 5]):
    total += a * b
print(total)
  1. ValueError
  2. 14
  3. IndexError
  4. 10
Answer and explanation

Answer: B. 14

Explanation: zip stops as soon as the shorter input runs out, without any error. The pairs are (1, 4) and (2, 5), so the total is 4 + 10 = 14.

Previous: enumerate() numbers a list of names starting from 1. What line is printed? · Next: The inner loop's range depends on the outer loop variable. How many times does…

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