Function error


#1



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


My code is saying "Oops, try again. Your function failed on the message yes. It returned 'yes' when it should have returned 'Shutting down'"


I think i had follow the instruction properly. So i think it should return "Shutting down" when s = "yes" or return "Shutdwon aborted" when s="no" else it should return "Sorry"


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


#2

You can do this:

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

The example code was just for reference, probably. :slight_smile:


#3

As soon as your function started, 's' was returned, ending the function right then and there. Also, your if-statements are outside of function, which means that 's' should not be defined at all since it is the parameter of the function and can only be used inside the function.


#4

Just change the shut_down on if elif and else to return. :slight_smile:


#5

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