Receiving error messages for correct total prices


#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 pear, 3 oranges and 7 bananas resulted in 35.5 instead of the correct 31.5"
"Oops, try again. calling compute_bill with a list containing 2 apples and 7 bananas resulted in 28 instead of the correct 24"
"Oops, try again. calling compute_bill with a list containing 3 pears, 3 oranges and 9 bananas resulted in 49.5 instead of the correct 37.5"


I get these error messages, even though going through all of the prices add up to the number that the error says isn't correct. What did I do wrong?


shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

# Write your code below!
def compute_bill(food):
    total = 0
    for item in food:
        if stock[item] > 0:
            total += prices[item]
            stock[item] - 1
    return total


#2

If you wanna subtract something, then you write:

stock[item] -= 1;

which is same as writting stock[item] = stock[item] - 1


#3

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