What's off with this code?


#1
  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"
else:
    return "Sorry"

#2

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.

EXAMPLE:

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

#3

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"
	else:
		print "Sorry"

#4

@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.


#5

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