Getting error on defining functions


getting following error message: Oops, try again. Your function failed on the message yes. It returned 'yes' when it should have returned 'Shutting down'

following are my code:

def shut_down(s):
return s

if s=="yes":
shut_down("shutting down")
elif s=="no":
shut_down("shut down aborted")


Nothing else is going to run since whatever gets passed in gets immediately returned. This line may be removed.

s is the parameter to receive the arguments "yes" or "no". We do not set it in the function else we wipe out the argument that was passed in to the function.


Those are the two main calls. Now lets look at the rest of the code.

It is very dangerous to call a function from within itself. This is known as recursion and takes careful planning. But, it is not needed here.

if s == "yes":
    print "shutting down"

Same applies in the elif and the else. See if you can fix it from here.


thanks for your help;
Actually I am trying to do codecademy's following exercise and I tried many different ways including your guidance, however I am getting error all the time; Note I am a new coder and seems I'm doing something wrong. Appreciate if your provide some help in this matter.
Following is the exercise I am attempting to do:

1: First, def a function, shut_down, that takes one argument s. Don't forget the parentheses or the colon!
2: Then, if the shut_down function receives an s equal to "yes", it should return "Shutting down"
3: Alternatively, elif s is equal to "no", then the function should return "Shutdown aborted".
4: Finally, if shut_down gets anything other than those inputs, the function should return "Sorry"

in the Hint they mention following instructions:
- Ensure your function outputs appear exactly as shown!
- Also, ensure your function returns the above values rather than printing them.


That line you have correct.

def shut_down(s):

Your function is to ask two questions: Did the user input "yes", or, did the user input "no"? Otherwise revert to default. This is an if..elif..else statement.

The blocking looks like what you have...

if ___:

elif ___:


My earlier example uses print, however we read in the instructions it should be return.

    return "Shutting down"

See if you can piece this altogether. You should have enough information to work with.


thanks for your help, it did work.
truly appreciate your help :))


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