Loading exercise...

Exercise: Tuple Sums

Avatar image for Ziggy

Ziggy on Nov. 4, 2026

Can’t remember that enumerate was mentioned in the lessons.. my code:

data = ((1, 2), (3, 4))
for row in data:
    print(f"Row {data.index(row) + 1} sum: {sum(row)}")
Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Nov. 9, 2026

@Ziggy you’re right, you don’t need enumerate() for this exercise. The main solution tracks the row number with a counter variable:

index = 1
for row in data:
    print(f"Row {index} sum: {sum(row)}")
    index += 1

enumerate() only shows up in the solution notes as an alternative. If you’re curious, Python enumerate(): Simplify Loops That Need Counters covers it in depth.

Your code works and produces the expected output. One thing to watch out for with .index() is that it returns the position of the first matching item. If two rows have the same values, they get the same row number:

>>> data = ((1, 2), (1, 2))
>>> for row in data:
...     print(f"Row {data.index(row) + 1} sum: {sum(row)}")
...
Row 1 sum: 3
Row 1 sum: 3

That doesn’t happen with the data in this exercise, but a counter (or enumerate()) avoids it.

Become a Member to join the conversation.