What's off with this code?

  1. Review: Functions

File "python", line 4
SyntaxError: 'return' outside function

I don't really understand what the error message is trying to tell me.

def shut_down(s):
    return s
if s=="yes":
    return "Shutting down"
elif s=="no":
    return "Shutdown aborted"
    return "Sorry"


Syntax my friend. Fix the indentation problem and it will work.

Also as a note return stops running any more of the function, so if you want to hit the rest of the if statements then you will need to rewrite your code as well.


def indents(stuff):
    return stuff # indents are important in python


There's no need of returning it. Just remove the return s and try.
It would look like this:

def shutdown(s):
	if s == "yes":
		print "Shutting down"
	elif s == "no":
		print "Shutdown aborted"
		print "Sorry"


@zeziba is right. My code is also right and you did forget to indent your code. You can replace my code's print statements with return statements. But it would not print it to the console.


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