Stocking Out


I don't get what I'm doing wrong. Also, I've looked at other posts and haven't seen a single person use "else". Am I not supposed to use else?

Error message is:

File "python", line 26
SyntaxError: invalid syntax

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


If you can argue for why it's useful, sure, go ahead. Can you though? Does it help do what the function's purpose is?

else is only allowed as an optional second part of an if-statement. Yours is all by itself.


you only need to return total and make sure it is correctly indented.


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