Loops 10/13 - nested loops question

hello i cant get the third part please help, thankyou!
https://www.codecademy.com/content-items/9ce46bce7be2a52678343c17c1d7b24f/exercises/nested

Question 3
Within our sales_data loop, nest a secondary loop to go through each location sublist element and add the element value to scoops_sold .

By the end, you should have the sum of every number in the sales_data nested list.

my code:
sales_data = [[12, 17, 22], [2, 10, 3], [5, 12, 13]]

scoops_sold = 0

for location in sales_data:

for scoops_sold in location:

print(scoops_sold)

Output
12
17
22
2
10
3
5
12
13

from op-
Not shown in post, but currently indented correctly.
( I copy pasted wrong )

I think it wants you directly add up the values and print a single value after the loop rather than printing each value in turn.

If you’re posting code to the forums see How do I format code in my posts? which describes how to keep all the good stuff like indentation :slightly_smiling_face:.

Ok will do next time thankyou.

Exactly i need the total of all the numbers, but how do i do that in my code?

What would you do if you had a single integer value that you wanted to update it with a second value (summing the two values together). If you can do that once then doing so in the loop should be pretty similar.

1 Like