shut_down function issue


#1

I am getting below error:

Your shut_down function threw the following error: maximum recursion depth exceeded.

def shut_down(s):

if shut_down("Yes"):
    return("Shutting down")
elif shut_down("No"):
    return ("shutdown aborted")
else:
    return ("sorry")

#2

I'm getting a error as well: def shut_down(s)
is says i cant have the (s) in the parenthesis as its an "invalid syntax"


#3

Here's what I got. It works.
def shut_down(s):

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

I'm not calling the function on the if and elif, I'm calling the argument s.


#4

What you are doing is

if shut_down("Yes"):

This line is calling the function every time it get's to that statement.

You need to change it to the following,

if s == 'Yes':

While you can totally use a function in an if/else statement you need to have at the base level a comparative that actually gives something back to the if statement to compare,

In closing here is a solution to scratch your head over.

def shut_down(s):
    return ("shutting down") if s == 'y' else ("shutdown aborted") if s == 'n' else ("sorry")

#5

I struggled with this one, too, until it dawned on me that the 'if, else' statement needed to be part of the 'shut_down' fx.

Here is how I solved it:

def shut_down(s):
    if s == "yes":
        return "Shutting down"
    elif s=="no":
        return "Shutdown aborted"
    else:
        return "Sorry"
    
print shut_down("yes")
print shut_down("no")
print shut_down("wait, what?")

I added the print shut_down() examples at the end so I could visualize what I thought was happening.

edited to fix code format.


#6

tried your code do not use quotation marks use apostrophes :laughing::laughing:


#7

never mind it actually wasn't working


#8

here is the right code

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