Functions Review


#1

Im confused, i have been stuck here for a long while and i don't know what else to do. Im just stupid.
It kept saying "Your function failed on the message yes. It returned 'yes' when it should have returned 'Shutting down'"

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

Im honestly stuck here and i can't get out. Somebody help me quick please because i want to start another language before summer.


#2

You return the argument that's given to the function (read your code/execute it manually)


#3

if that's what i did, how do i fix that? and if not, and that's what im supposed to do then should i return s or .... im sorry im very slow with coding.. please be patient


#4

Ok i fixed it but im getting an error saying maximum recursion depth exceeded.
this is my code

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

#5

Your function calls itself each time it's called, in other words that's an infinite loop, except that it crashes when the call stack gets too big


#6

I tried something else.. but i don't get it .. how do i prevent this? Please explain a bit more, or give me an example


#7

Your function is using the variable that refers to itself - but it shouldn't be doing anything with itself so therefore it has no need to use that variable either. Your function shouldn't mention its name anywhere other than where it defines it in its header


#8

thanks so much, i got through it but now im stuck at another activity. If you can, please help


#9

is this under API(Application Programming Language)?