# A Day at the Supermarket

#1

A day at the Supermarket

my code seems okay but i always get an error

Oops, try again. calling compute_bill with a list containing 3 pears, 3 oranges and 8 bananas resulted in 45.5 instead of the correct 37.5

``````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(foods):
total = 0
for food in foods:
if stock[food] > 0:
#print food + str(stock[food]) + " " + str(prices[food])
total += prices[food]
stock[food] - 1
total

print compute_bill(shopping_list)``````

#2

this:

``stock[food] - 1``

will not reduce the stock, you need to update/re-assign `stock[food]`, how do you think you can do this?

#3

like this?

stock[food] = stock[food] - 1

i still get error

#4

yes, like that.

remove the function call:

``print compute_bill(shopping_list)``

it influences the stock before the exercise can do the validition.

#5

thanks! it finally worked

#6