Tuple Sums (Exercise)
00:00
This tuple sums exercise is starting to dive into nested collections. You should start by creating a tuple called data
that has two values, and each of those values are going to be a tuple again.
00:12 The first value should be a tuple that contains the integers one and two. The second value should be another tuple that contains the integers three and four.
00:20
And then with this nested tuple, you should write a for
loop that loops over data
, that’s the nested tuple, and then prints the sum of each nested tuple.
00:29 So the output should look like this: Row one, sum three, and row two sum seven. Row one means it’s referring to the first tuple, and then it’s summing up the two integers in there.
00:42 So that’s one and two, and the sum of these two is three. And then the second values, we’re talking about row two now, is a sum of seven, which is adding the two integer elements of that tuple together, which the elements are three and four, so that sum is seven.
00:57 And then you have a bit of formatting just so that it prints out telling you which row it is and then what the sum of the elements in that row are.
01:06 All right, give that a try and then you can watch me do it in the next lesson.
Become a Member to join the conversation.