Stocking Out


#1



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
else:
^
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]
        else:
            print "Item out of stock"


#2

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.


#4

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


#5

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