Nested Looops - Learn Python 3 Exercise 10/13

Hi everyone!

I am doing exercise 10/13 on nested loops right now, I continued to fail and checked the solution but now I have the following question:
why does scoops_sold += elements need to be added in the nested loop:

for location in sales_data: print(location) for scoops in location: scoops_sold += element print(scoops_sold)

It was not necessary during previous exercises and steps, which were also on nested loops.
Here is the link to the exercise, and I also included a screenshot. Would be amazing, if someone could explain it to me because I really want to understand the logic and what I need to do. Looking forward to some replies, thank you all very much in advance :slight_smile:

I think you used the wrong name for the variable there:
either scoops should be element
or element should be scoops
It seems like those should be the same variable.

Here’s a similar example:

list_of_lists_of_ints = [
    [2, 4, 3],
    [1, 6, 5],
    [7, 8, 1],
    [6, 2, 0]
]

# want to get total of nested list, using nested loops
total_so_far = 0

for sublist in list_of_lists_of_ints: # sublist is the inner list(s), one at a time
  for num in sublist:  # access each number in inner list as "num"
    total_so_far += num  # add each number to the total

# total_so_far now contains the total for everything
print("total: ")
print(total_so_far)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.