11. Making a purchase


#1




Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5 is the error I keep getting and I'm not sure why?


It's supposed to be returning the total of the items for any list of food and I can't figure out what is wrong here.


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

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

        
def compute_bill(food):
    total = 0
    for item in food:    
        total += prices[item]
        return total


#2

unindent this line once, you don't want it in your for loop


#3

OMG, I've been on this for 2 days now thank you so much


#4

6 posts were split to a new topic: Getting wrong total


#10

Makes sense. Thank you again :slight_smile:


#12