Stocking Out


#1

def compute_bill(food):
total=0
for item in food:
if(stock[item]>0):
total+=prices[item]
stock[item]-=1
return total

Whats wrong with this?
Its showing error: "Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 0 instead of the correct 7 "


#2

a function ends the moment a return keyword is reached, if the return keyword is reached in a loop, the loop simply breaks and the function ends


#3

oh so do I need to return the total after the function?


#4

no, return is only valid inside the function. You need to place return after the for loop


#5

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