Need help, can anyone tell me what's wrong with the following code?Console shows 4 instead of 10.5


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):
for item in food:
total += prices[item]
return total
print compute_bill(shopping_list)


a function ends the moment a return keyword is reached

so your function ends in the first run of your loop


can u please help me to correct it?


you need to place return outside the loop so the whole loop can run and the function doesn't end in the first iteration/run of your loop


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