17 Review:Functions


#1

Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: 'return' outside function (python, line 4)


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


#2

Hi try top remove the return message


#3

you need to "tab" the ifs and the returns.

right now it seems that your function has only one instruction: return message.

Tab the other instructions to put them inside your function


#4

i did that. Now its saying did you create a function called shut_down? And its already created


#5

@tobuscus45,

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

#6

this code doesn't work for me...


#7

Hi can you post your code?


#8

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

with indentations
but it doesn't put the indents on the post


#9

so its like that

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

if so try to refresh the page. if that dont work , post the error you get


#10

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

I get the error "Oops, try again. Did you create a function called shut_down?"

I have no idea what I'm doing wrong?


#11

Hi you should add " " around yes and no inside your if and elif condition.


#12

Wizmarco, thank you - that worked perfectly. Just so I understand, yes and no are considered strings for the s argument, correct?


#13

i figured it out, I was supposed to use "" instead of ''


#14

if's should be indented once (tab or 4 space) returns should be indented 2 times.

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


#16

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

this worked for me


#17

Im pretty sure all you need to do is remove return message this is my code

def shut_down(s):

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

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

else:
    return "Sorry"

#19

I don't understand what is wrong with my code, it throws the error "your function failed on the message yes. It returned 'sorry' when it should have returned 'Shutting down'.

Can somebody help please?

def shut_down(s):
if s == "Yes":
return "shutting down"
elif s == "no":
return "Shutdown Aborted"
else:
return "sorry"


#20


Hello!
I have a question.

I don`t know which part is incorrect and what does mean under message.

please help me.


#21

Hi you should remove the returns s

def shut_down(s):
    return s <== Remove this one 
    .........

#22

Thank you!
I solved this problem thanks to you.
but I wonder the reason.
In the Review,
def speak(message):
return message

if happy():
speak("Im happy!")
elif sad():
speak(I
m sad.")
else:
speak("I dont know what Im felling."

What is the deffrence between review and my code?