Learn Python 3 Carly's Clippers


Learn Python 3

Carly’s Clippers

Can someone explain to me the differential as to why this is occurring.

I am doing Carlys Clippers though using old teaching to learn the process and correctly do it. i.e. - the assignments from the practice.

Both see the same but they are not working in the same process when using the same mentality.


We have provided the list sales_data that shows the numbers of different flavors of ice cream sold at three different locations of the fictional shop, Gilbert and Ilbert’s Scoop Shop. We want to sum up the total number of scoops sold.

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

scoops_sold = 0

for location in sales_data:
  for element in location:
    scoops_sold += element


Iterate through the prices list and add each price to the variable total_price .

prices = [30, 25, 40, 20, 20, 35, 50, 35]

total_price = 0

for price in prices:
  for value in price:
    total_price += value

Should be the same mentality though the top is lists within a list and the bottom is just a list. Though all said this is the error I continue to get.

Traceback (most recent call last):
File “script.py”, line 11, in
for value in price:
TypeError: ‘int’ object is not iterable

Both from my understanding are ‘int’ values, the top works but the bottom doesn’t.

Thank you for any feedback.

You already said yourself why the bottom one does not work. The difference is that the array prices in the bottom example does not contain any lists, it just contains integers.

What you are doing here however is trying to loop trough a integer. The error is given because you can’t loop trough integers since they are not iterable.

removing the second for loop should fix your problem.

for price in prices: 
   total_price += price 

Hope this clarify’s things.