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


#1


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

Oops, try again. Your shut_down function threw the following error: maximum recursion depth exceeded

Replace this line with your code. 

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

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


#2

here:

if shut_down(s)== "yes":

you call the function inside the function, this is called recursion, given there is no base case, the recursion goes till infinity, but python has a safe guard built in, a maximum recursion can occur

s (the function parameter) contains the string you need to compare


#3

def shut_down(s):

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

i typed like this but it gives me a maximun recursion depth exceeded error


#4

shutdown() is still a function call, why would you want to call the function inside the function?


#5

oooooooouh i get it now! thanks!

one last question, is it possible that you can have a recursion with any kind of porpouse?
or it is always an error?


#6

well, if you have a bunch of folders with a bunch of sub-folders and you don't know how many, recursion is good, given you can't use a loop.

So yes, its useful, but when using recursion, always have a base case (you can google this), so the recursion doesn't reach its maximum depth


#7

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