Functions review problems


#1

https://www.codecademy.com/courses/python-beginner-c7VZg/4/1?curriculum_id=4f89dab3d788890003000096#

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")
else:
    return ("Sorry")

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


#2

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.


#3

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"

else:
    "I'm Sorry"

#5

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 == ...:

    else:


#6

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


#7

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