Review: Functions...HELP!


#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 5)

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


I just want my code to work


def shut_down(s):
    return s
    
if Yes():
    return("Shutting Down")
    
elif No():
    return("Shutdown Aborted")
    
else:
    return("Sorry")


#2

Hey, I see how the example shows it like this, but you're actually supposed to complete it a different way. You want it to all be part of one function; the shut_down function, so all of the if/elif/else statements would be inside of shut_down. Also, Yes() and No() aren't functions, so you will have to evalutate whether the argument, (s) is equal to the strings yes and no.

From the instructions:
if the shut_down function receives an s equal to "yes", it should return "Shutting down"
Alternatively, elif sis equal to "no", then the function shouldreturn "Shutdown aborted".
Finally, if shut_down gets anything other than those inputs, the function should return "Sorry"

Can you start this and then ask me more specific questions about what you're having trouble with? i want to see how for you can get by yourself :slight_smile:


#3

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

else:
    return 'Sorry'

Ok.
Now it is saying:

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

What does that mean???
And what am I doing wrong THIS time???


#4

it means that your return statement is not inside of a function. return is only used in functions, so to put all of

if (s) == 'yes':
    return 'Shutting down'
    
elif (s) == 'no':
    return 'Shutdown aborted'

else:
    return 'Sorry'

this inside of shut_down, it needs to be indented. :slight_smile:

Once, this is done, you're going to have a logical problem though, because you return s immediately. When a return command is reached, the function ends. Just get rid of
return (s)
and your program should work after you've indented :slight_smile:


#5

OOOOOHHHHHHH!!!!!
XD
Makes sense...


#6

Thanks a million!!!
Still getting used to coding, so thanks for the support!!!


#7

It's no problem!
You were receptive to what I said, and I appreciate it :slight_smile:
Have a great day!


#13