def shutdown(s): return s if yes(): return("Shutting down") elif no(): return("Sborting shut down") else: return("Sorry")
changed some code
def shut_down(s): return s if s == yes(): return("Shutting down") elif s == no(): return("Sborting shut down") else: return("Sorry")
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)
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" else: return "Sorry"
i added quotation marks for "yes" and "no" just realised
Oops, try again. Your function failed on the message no. It returned 'Shutting down' when it should have returned 'Shutdown aborted'
s == was very good, i just told you to convert
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:
this will print
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.