I'm trying to sum up a list of numbers from the list but for some reason it just kept showing TypeError, can somebody tell me why and how I can fix it?
portfolio = [('AAPL',5, 140),('FB',3, 330)]
for i in portfolio:
sum_value = 0
stocks = list (i)
item_value = stocks[1] * stocks[2]
print(sum(item_value))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-56-5825164afaac> in <module>
5 stocks = list (i)
6 item_value = stocks[1] * stocks[2]
----> 7 print(sum(item_value))
8
9
TypeError: 'int' object is not iterable
item_valueis an integer, you can not use thesum()function on only one integer. Could you show the expected output?item_valuecontains the result ofstocks[1] * stocks[2]. So it's just an integer.