Help, I don't know why my code isn't working :(


#1


https://www.codecademy.com/courses/python-beginner-c7VZg/4/1?curriculum_id=4f89dab3d788890003000096#

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

I thought that my code would return how I wanted it to, but it didn't.

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

#2

the example is just there for your to remind of syntax, but your program follows a very different design

Please use the example as such (syntax reminder) not to design your program


#3

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

I tried to fix the issues, but i'm still really stuck.


#4

slightly better, but a function ends the moment a return keyword is reached, so your function ends way to early

also, don't call the function inside the function, which is called recursion, but given there is no base case, its basically endless, sort of like an infinity loop but with functions


#5

def shut_down(s):

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

Thanks I figured it out :slight_smile:


#6