17/19 return outside function


#1

Hi,
This is the code that I put in

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

And this is the problem:
File "python", line 5
SyntaxError: 'return' outside function

I don't know how to fix it. Any advice?


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

this is right


#4

I inserted

def shut_down(s):

if s == "yes":
return "Shutting down"
elif s == "no":
return "Shutdown aborted"
else:
return "sorry"

but it doesnt work, it shows the message:

File "python", line 3
if s == "yes":
^
IndentationError: expected an indented block


#5

You need indentation like how franzisak said

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

#6

i couldn't seem to get mine to work either, but it does when i use yours - thanks ryebread4


#7

Funny, had the exact same code as the ones above.. I only had the s == "Yes", changed it to "yes" (lower case "y") and it finally worked.. anyone know why that is?


#8

as per instructions its given 'yes'.
it will not work if we dont type char according to instructions.


#9

I fixed mine


#10

The problem is the function def and the spaces after it.
What netninja69513 make was define the variable of shut_down(s), that is made by the spaces.


#11

Why did it say that I had exceed the maximum recursion depth when I wrote down that shut_down(s)=="yes"?


#12

whenever i try this part, it always says "did you make a function called " shutdown

I don't know what to make of this. please help


#13

i realized i was doing something very stupid in that i made shutdown two separate words like "shut down" and so the program wasn't working but the way that franzisak said to do it works fine!


#14

thanks franzisak..indeed it's a legit solution


#16