Functions review problems


Your function failed on the message yes. It returned 'Sorry' when it should have returned 'Shutting down'

def shut_down(s):

if(s) == ("Yes"):
    return ("Shutting down")
elif(s) == ("no"):
    return ("Shutdown Aborted")
    return ("Sorry")

I keep getting this error and am confused at what to do.


Perhaps a bit too much syntax?

if s == 'yes':
    return "Shutting down"

Unneeded parentheses only clutter up the code and make errors harder to spot.


I’ve put the colons after yes and no which was suggested in other comments but I keep getting a syntax error. Can you tell me why?
def shut_down(s):
return s

if shut_down(s):
    s == 'yes':
    return "shutting down"

elif shut_down(s):
    s == 'no':
    return "shutdown aborted"

    "I'm Sorry"


You’ve changed it too much, and it should not replicate the rather bad example given that has thrown so many learners under the bus. Your first example is close, but just needs the tiny adjustment I suggested. DO NOT call the function, and do not let the first line of the function be return s. Forget the example given.

def shutdown(s):
    if s == ...:

    elif s == ...:



Not OP, but your comment really helped me out where I was stuck. Thanks!


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