Stocking Out


#1



Oops, try again. calling compute_bill with a list containing 2 apples, 2 pears, 2 oranges and 8 bananas resulted in 41.0 instead of the correct 33.0


I don't know also what is a simple way to run my code to check for errors? Thanks.


Replace this line with your code. 
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

Hello :slight_smile:

Problem is in this line:

stock[item] - 1

This statement does not change the value of stock[item], you have to use a = operator, just like you did here:

total += prices[item]

I don't know also what is a simple way to run my code to check for errors?

Sorry, but I do not understand your question. May I ask you to rephrase it?


#3

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