# Stocking Out (right results but error)

#1

Hello,

I have written my code, and when it is executed, the result is correct.
However, there is an error "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} "

``````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:
if stock[item] > 0:
total += food[item] * prices[item]
stock[item] = stock[item] - food[item]

n = {"apple": 1, "banana": 2, "orange": 3}
print compute_bill(n)
print stock``````

#2

Hi @hegy88 ,

What are you trying to do with `food[item]` here? ...

``total += food[item] * prices[item]``

This will not reduce `stock[item]` properly ...

``stock[item] = stock[item] - food[item]``

Instead, subtract `1` from the particular `item` involved in the transaction ...

``stock[item] = stock[item] - 1``

Codecademy does not want you to make this call during the current exercise ...

``print compute_bill(n)``

Save it for the next exercise.

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.