Cant find mistake in Functions Review


def shutdown(s):
    return s
if yes():
    return("Shutting down")
elif no():
    return("Sborting shut down")


changed some code

def shut_down(s):
    return s
if s == yes():
    return("Shutting down")
elif s == no():
    return("Sborting shut down")

i get the error
_ File "python", line 4
SyntaxError: 'return' outside function_


a function ends the moment a return keyword is reached. you should also nest the conditions inside the function:

def example():
  if True:
     print "if inside the function"

you will need to change some indent in your code (see my example)

also, yes and no are just strings, use quotation marks and no parentheses.


Ok I have changed some things using your advice, but I get the error Oops try again. Did you create a function called shut_down?

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


i added quotation marks for "yes" and "no" just realised

error now:
Oops, try again. Your function failed on the message no. It returned 'Shutting down' when it should have returned 'Shutdown aborted'


your s == was very good, i just told you to convert yes() and no() into string, no need to remove s==, which based of your latest code, not your first one


worked! Thank you for the help.


do you also understand why it worked?


yes, s is equal to a string and strings need to be in "" and if you dont have it, it will error.


so now you could add a function call (at the end of your code, with no indent) to see your function in action:

print shut_down("yes")

this will print Shutting down


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