Exercise 11/13 - A day at supermarket

#1

Hello,

I think I'm completly missing the point of this exercise.. Can someone help me??

I keep getting the error

> Oops, try again. compute_bill(['apple']) resulted in a TypeError: unsupported operand type(s) for +: 'int' and 'str'

``````shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}``````

`````` def compute_bill(food):
total = 0
for i in food:
total = total + i

#2

I'm having the same problem.. and what happened to Q&A?

#3
``````def compute_bill(food):
total= 0
for item in food:
total += prices[item]

#4

Logic...

Thank you for the help!

#5

we have to add price of the item to the total that's why we are using prices[item].
If we add only item to the total total = total + i that is not meaningful.

total = total + prices[i]
In this way we add the prices of item to the total.

#6

Thanks for the help

#7

thank you bro...but is it the correct code??

#8

i have that code:
shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
def compute_bill(food):
total = 0
for key in food:
total = total + food[key]