12. Stocking Out


#1


https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/2/3?curriculum_id=4f89dab3d788890003000096#


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.

Thanks!


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


#2

here:

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


#3

Thank you!

That makes sense. Removed the equals and it works.


#4