You want to average the prices in the fruit list! I even extracted the price from the list I think I can use the sum, but it's stuck.
fruit = ["Apple", 1020] ["Orange", 880] ["Grape", 3160]
sum=0
for i in fruit:
print(i[1])
#sum+=i
TypeError: unsupported operand type(s) for +=: 'int' and 'list'
It pops up like this. What should I do?
list for average sum
I understand that the average is usually calculated like this.
fruit = ["Apple", 1020] ["Orange", 880] ["Grape", 3160]
num = [i[1] for i in fruit]
plus = sum(num)
average = plus / len(num)
print(average)
>> 1686.6666666666667
© 2024 OneMinuteCode. All rights reserved.