# Making purchase error

#1

returning oops try again compute_bill(["banana","apple","orange","pear"]) returned 4 instead of 10.5

``````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
}

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

Making a purchase showing wrong output
#2

a function ends the moment a return keyword is reached, if this happens in a loop, the loop breaks

Place return outside the loop so the whole loop can run

#3

still it is returning 4 instead of 10.5

#4

can i see an updated version of your code? Or am i suppose to guess what is wrong?

#5

print total 4 instead of 10.5

``````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
}
def compute_bill(food):
total=0
for item in food:
total+= prices[item]

print(compute_bill(shopping_list))``````

#6

the return keyword is still reached in the first iteration of the loop, this means, at the end of the first iteration the loops breaks. (so only the first item of `food` get added to total.

Place the return outside the loop, so the whole loop can run

#7

thanks it worked well for me

#8