Learn Python 3
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: print(location) for element in location: scoops_sold += element print(scoops_sold)
Iterate through the
prices list and add each price to the variable
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.