Review: Functions


#1



I've been stuck on this problem for about an hour now. I have really tried to dissect what I'm doing wrong and can't seem to figure it out. If someone can point me in the right direction that would be greatly appreciated.

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


It keeps displaying this error code
File "python", line 8
else shut_down():
^
SyntaxError: invalid syntax

Any help is greatly appreciated.



#2

You are getting the error since else conditions in python don't take a condition, they run whenever the rest of the conditions in that chain return False. Also, your conditions will never pass since you are calling the function to check the condition, without passing any parameter (and if you do, it'll stay stuck in an infinite loop, since it will keep calling itself).
This should fix it:

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

#3

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