# Supermarket checkout gives error but code appears correct

#1

Oops, try again. stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}

This is the printout and I assume this is supposed to be what happens.
banana
instock 6
price 4
total 4
pear
instock 15
price 3
total 7
(7, {'orange': 32, 'pear': 14, 'banana': 5, 'apple': 0})
None

``````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 item in food:
print item
price = prices[item]
instock = stock[item]
print "instock",instock
if instock > 0:
print "price",price
total = total + price
print "total",total
stock[item] -= 1

stuff = ["banana","pear"]

print compute_bill(stuff)``````

Thanks for any help
Peter

#3

There is way more code than required for this exercise. We are only computing, not printing. Keep your code as simple as you can. The dictionaries themselves are the only variables you need, apart from `food`, `item` and `total`.

``````    total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] -= 1