Why should compute_bill(['apple']) return 2


#1



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


Oops, try again. compute_bill(['apple']) returned 0 instead of 2


the code should have passed


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 i in food:
        print(prices[i] * stock[i])
        total += prices[i] * stock[i]
    return(total)

print(compute_bill(shopping_list))


#2

this function takes a list as input (which represents a user buying things from your store), bit unfair that the customer gets charged prices[i] * stock[i] for buying a single item. This mean, buying 1 banana would cost me 24$, one banana should cost 4$.


#3

ok i got it, i need to calculate the total price with buying one for each fruite, thanks~


#4