Stocking out problem


What’s wrong with my code? I think the result is correct, but I get 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}

def compute_bill(food):
    total = 0
    for item in food:
        if stock[item] > 0:
            total += prices[item]
            stock[item] -= 1
    return total

print compute_bill(shopping_list)


they do not want you to decrease stock while computing the bill. so you have to remove above line


HI like the error says you should pass the lesson with the stock equale to…

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

so when you call the function with shopping_list it remove one item inside the stock. and the stock become

stock =  {
    'orange': 31, 
    'pear': 15, 
    'banana': 5, 
    'apple': 0

But you could do somthing you could add one item each item inisde stock like that

stock = {
    "banana": 7,
    "apple": 1,
    "orange": 33,
    "pear": 15

But not to all of them just the one inside the shopping_list.


easy way you could remove the call function and pass the lesson and call the function in the next lesson.