11/13 help


This is my code:

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3}

def compute_bill(food):
    total = 0
for item in food:
    total += prices[item]
return total

It says this is what's wrong:
File "python", line 19
SyntaxError: 'return' outside function
Help plz?



is your return indentet 4 spaces?


nope, no indent either. just:
return total


i dont have any indent for return total, so whats wrong?


It needs to be indented 4 spaces like this:

def my_function():
    return True

Everything that's part of your function definition needs to be indented 4 spaces, or more in some cases, for example if there is a loop inside your function.

def my_function():
    for x in [1, 2, 3]:
        # this code is inside the loop that's inside of the function definition
        print x

    #return statement goes into the function definition
    return True

#more code that's not indented 4 spaces will not be part of the function
print "This is not part of the function."


@eveat is right. Also, please always format your code the way I did (use backticks; check your post) from next time. Thanks!