practicepython.in
python exercises
171 exercises

Daily #15 · 13 October 2026

Summing it twice Medium

What does this print?

squares = (n * n for n in range(4))
print(sum(squares), sum(squares))
  1. A14 14
  2. B14 0
  3. C0 14
  4. Draises TypeError
Show the answer

B: 14 0

Why: A generator produces its values once and is then used up. The second sum finds nothing left and returns 0. Use a list if you need to go through the values more than once.

Play today’s puzzle →