Can anybody solve this?


#1



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


i m getting this error every time i submit the code.

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


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


#2

What is the purpose of the first return statement? All that will do is return the variable s and stop executing the rest of the code.

Also, elif statements should be explicit (i.e. elif s == "no":)


#3

hello nedwards,
i have tried the code by removing return s on second line, but still i was getting error saying have you created a function called shut_down()


#4

Can you post the full code of what you have now?


#5

yes for sure i have shared a code which i have been trying since 1hr, and i have shared the link also so that everybody can see the error.


#6

I meant the revised code (without the first return statement), can you post all of that?


#7

see the error


#8

That's just a link to the exercise - which contains my code, not yours.

Can you post your revised code here?


#9

Try this code on your python compiler and see what happened.

code starts here

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

end of code


#10

Okay, the error message is technically wrong, but what's causing your code to fail is your elif no: line.

Conditionals should always be explicit, and by that I mean the following:

if s == "yes" or s == "Yes" <-- explicit

if s == "yes" or "Yes" <-- implicit, because it's implying that it should be checking if s == "Yes", rather than explicitly saying so. There are further reasons why this wouldn't work, but I won't go into them now.

So your elif statement needs to explicitly check if s == "no".

If you fix that (and properly capitalise "Sorry" on your last return line), your code should pass.


#11

ok thnks bro for helping...!!
have a good day..!!


#12

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