12-Stocking out


#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! total = 0
def compute_bill(food):
    total = 0
    for x in food:
        if stock[x] > 0:
            total += prices[x]
            stock[x] -= 1

It returns,Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in None instead of the correct 7.What is the problem please,somebody help me with the correct code.

#2

Hi @aliyu123 ,

Your compute_bill function does not have a return statement, so it returns the value, None. You need to add this to the end of the function definition ...

return total

Make sure that you indent the statement correctly, so that it is part of the function, but not part of the for loop.