Review: Functions


#1



Help. Im stuck at review: functions


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


itsaysthat the 's' on if s == "yes" is not defined


#2

The above line causes the function to terminate before even executing.

Good thing the program did not run or this would cause an infinite loop...

shut_down ("Shutting down")

Please post a link to this exercise so we can review the instructions. Thanks.


#3

https://www.codecademy.com/en/courses/python-beginner-c7VZg/4/1?curriculum_id=4f89dab3d788890003000096
here is the link


#4

The function is to check the inputs for yes or no and return the prescribed phrases, or Sorry otherwise. Your if statement is correct but is missing the return statements.


#5

Hey, could you please post the full solution to this exercise? I am not able to get through:(


#6

The solution is not that difficult to reach if one applies one's self. The instructions are pretty clear.


#7

Applying the instructions to the t!
still causing errors


#8

Let's see what you have...


#9

Received the flowing error:-
File "python", line 5
SyntaxError: 'return' outside function

Here's what I did:-
def shut_down(s):
return s

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

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


#10

before the above effort I tried following the example code as well
that didn't work either


#11

Please help:( ASAP please
Getting so frustrated right now


#12

You are so close but have the same mistake as the Opening Post of this topic. See the reply to that one for the correction.


#13

It's still different, please post the full solution?


#14

SyntaxError: 'return' outside function
Please tell me what this error means


#15

def func():

return

When return is not indented, it is not in the function code block. Hence, return outside function.


#16

So here are the changes I made:-
def shut_down(s):
return s

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

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

else:    
    return "Sorry"

And here's the error message that popped up:-
Your function failed on the message yes. It returned 'yes' when it should have returned 'Shutting down

What's wrong?


#17

I have indented return s but it didn't show up in the question I asked just now


#18

def shut_down(s):

if s.lower() == "yes":
    return output("Shutting down...")

elif s.lower() == "no":
    return "Shutdown aborted"

else:    
    return "Sorry"

THIS WORKED! FINALLY!


#19

That's good. One more correction...

return output("Shutting down...")

should be,

return "Shutting down..."

#20

5 posts were split to a new topic: 'return' outside function,