#17: review function


#1



Replace this line with your code.


#2

this code should not have worked, what is giving me a green check mark?

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

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

else:
    return "Sorry"

shut_down(s)
print(s)


#3

Hi, @at_1965 ,

We would like to copy your code, exactly as it was when you submitted it, so we can test it. But for us to do so, all of the details need to be visible, including the indentation.

It is important to format code in its entirety when you post it. But part of your posted code is not formatted.

See How do I format code in my posts?, then either post your code again with proper formatting, or edit your original post.


#4

There's a similar problem with my code too.

def shut_down(s) :
return s

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

the error i am getting is

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

Please help with the code


#5

hi @codemaster03299 could you please provide a link to your code because according to your code as you know python is very strict about indentation and if the function or the if condition are at the same indentation then python will execute the code as though the return statement is outside the if statement.

Inshort there is an indentation problem on line 5.
here check my code :slight_smile:

i am providing the link as posting the code here will create indentation problems.

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


#6

Hey...ronit1710, thanks for looking into the problem. Python really is
strict about indentation, I have learnt that now. Though, I realised what
was the error yesterday only, I am really thankful for the help you
provided.
Hope we will interact in future as I delve into the depths of programming.


#7

Most welcome @codemaster03299. Surely we will interact in future. Mark this
as the solution if u feel it appropriate. :grinning::grinning:


#8

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


#9

Here is my code :

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


#10

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