Stocking out


#1

I'm having a trouble with acceptance of my code, could anyone advise on the below outlined?
Thank you

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

Stocking Out
#2

P.S. indentation is ok, but the following message appears:

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

#3

You're returning before the loop has finished


#4

I tried and managed my code to be accepted. Here is the right answer:

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


#6

strange.. I've the same code but it results the right answer, however it gives following error:
"stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}"

I can't manage


#7

could someone help me out here, my code is correct, however the error that shows says the total is 36$, whereas the correct total should be 40 (which my code generates)

Oops, try again. calling compute_bill with a list containing 3 pears, 2 oranges and 7 bananas resulted in 40.0 instead of the correct 36.0

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

anyones help is appreciated at this point, thanks


#8

guys, it worked for me this way: