Learn Python 3 Carly's Clippers

https://www.codecademy.com/courses/learn-python-3/projects/carlys-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.

https://www.codecademy.com/courses/learn-python-3/lessons/learn-python-loops/exercises/nested

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:
  print(location)
  for element in location:
    scoops_sold += element
    
print(scoops_sold)

https://www.codecademy.com/courses/learn-python-3/projects/carlys-clippers

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:
  print(price)
  for value in price:
    total_price += value
print(total_price)

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.
example:

for price in prices: 
   print(price) 
   total_price += price 
   print(total_price)

Hope this clarify’s things.

1 Like