12. Stocking Out



Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 9 instead of the correct 7

Would seem like I'm following the steps and my error/mistake may be simple. Would like to both know what I have wrong and why it's incorrect.


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



if stock[item] >= 0:

because you use greater or equal to zero, people can also buy when you have zero in stock.

your code can also develop a negative stock


Thank you!

That makes sense. Removed the equals and it works.