Stocking Out -- Issue with stock and return value


#1



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


When I try to run the following code, it keeps popping up errors with the stock-count:

"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}"

When I remove the last line "compute bill(food)" it gives me this error:

"calling compute_bill with a list containing 2 apples, 1 pear and 7 bananas resulted in 23 instead of the correct 27"


I'm not sure why this code isn't giving me the right answer; I've tried different variations and looked at the other posts but nothing seems to address the same issue.


**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] > 1:
            total = total + prices[item]
            stock[item] = stock[item] - 1
    return total

food = ["apple", "banana"]

compute_bill(food)**


#2

here:

if stock[item] > 1:

if you have 1 item left in stock, you don't want to sell it? If i owned a shop, i will be happy to sell even the last item (more profit)


#3

Oh dear, that makes sense. Not sure how I overlooked that!

Many thanks!


#4