12. Stocking Out - Error


#1



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

"""Error message: Oops, try again. calling compute_bill with a list containing 3 oranges and 7 bananas resulted in 32.5 instead of the correct 28.5."""

#What's wrong and how do I resolve the problem?


Update - Problem resolved - alteration was changing stock[item] - 1 to stock[item] -= 1


#2

look at this code:

i = 5 
print i # 5
print i + 5 # 10
print i # 5
i = i + 5
print i

see how you can just temporary at 5 to a variable? And how to update it? Now look at your stock reduction


#3

Thanks, problem solved.


#4