Functions 17/19 "Review: Functions" HELP


#1

def shut_down (s):
if s =="yes ":
return "Shutting down"

elif s=="no":
     return "Shutdown aborted"

else:
    return "Sorry"

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


#2

remove the space between the s and " and see if that works


#3

also remove the space between down and (s)


#4

def shut_down(s):

if s =="Yes":
    return "Shutting down"

elif s =="No":
    return "Shutdown aborted"

else:
    return "Sorry"

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

Please suggest what is wrong here


#5

this should work fine it worked for me

def shut_down(s):

if s == "yes":
    return "Shutting down"
elif s == "no":
    return "Shutdown aborted"
else:
    return "Sorry"

shut_down("yes") :slightly_smiling:


#6

yyooo dude it works good job 606pm


#7

I typed the exact same code but it doesn't work. All I get is
File "python", line 3
if s == "yes":
^
IndentationError: expected an indented block
and here is my code
def shut_down(s):

if s == "yes":
return "Shutting down"
elif s == "no":
return "Shutdown aborted"
else:
return "Sorry"

shut_down("yes")
Any ideas?? Thank you


#8

Hi its could be a indent problem try that its your code with the right indent

def shut_down(s):

    if s == "yes":
        return "Shutting down"
    elif s == "no":
        return "Shutdown aborted"
    else:
        return "Sorry"

shut_down("yes")

#9

Thank you!!! That works perfectly!!


#10

606pm,

Why did you put shut_down("yes") at the end of all of that? Could you please explain?

Thanks,

Jackson


#12

yes and no should be written in all lower case.
the input is yes not Yes. because you are using 'Yes' and the computer is inputting 'yes' it is going by else : return 'Sorry'. Worked for me


#13

I got the sam problem with 606pm's code but wizmarco worked great.


#14

you can try this , worked for me

def shut_down(s):
if s == "yes".upper() or s == "yes".lower() or s == "yes".capitalize():
return "Shutting down"
elif s == "no".lower() or s == "no".upper() or s == "no".capitalize():
return "Shutdown aborted"
else:
return "Sorry"


#15

ef shut_down(s):

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

:grin:

It works!!


#16

Thank you for the tip.


#17

606pm it doesn't work:

File "python", line 5
SyntaxError: 'return' outside function


#18

Hi instead of return try to use print


#19

No, but I found out where the problem was. All the if conditions must be indented as part of the function itself and (everything from def to "Sorry") and then there's another line needed that will call the function for either (yes) or (no).


#20

What about mine?

def shut_down(s):
return s

if yes(s):
    return "Shutting down"

elif no(s):
    return "Shutdown aborted"

else:
    return "Sorry"

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


#21

HI to all the people that will have a problem in this lesson also to @lechaim

FUNCTION 17/19

DO you know ho to create a function?
Do you know how to create a if statement inside a function that will use the parameter of the function?
TO those question I will respond for you "YES, WE DO!"
This Lesson doesn't aske you to do something you don't know it only aske you to...

01. First, def a function, shut_down, that takes one argument s. Don't forget the parentheses or the colon!

def shut_down(s):

The this part is about the if statement inside the function
02. Then, if the shut_down function receives an s equal to "yes", it should return "Shutting down"
the if condition is write this part s equal to "yes" so inisde it you will do

def shut_down(s):
    if s == "yes":
        return "Shutting down"

03. Alternatively, elif s is equal to "no", then the function should return "Shutdown aborted".

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

04. Finally, if shut_down gets anything other than those inputs, the function should return "Sorry"

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

AND

if you want something to be print just add this line at the end of your code

print shut_down("yes")

Hope that could help you