17.review functions NEED HELP

Thank you for your awesome explanation!

1 Like

This still doesn’t work for me!

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

what is the mistake I have done?

1 Like

You should be seeing this in the console window:

File “python”, line 4
if s == ‘yes’:
^
IndentationError: expected an indented block

If yes then see @greentreemee 's post above. Your if, elif and else statments need to be indented.

4 Likes

yes.I saw the post.Got the same thing, now corrected it! So thanks! @jagking

1 Like

I followed your instruction and that worked, but actually did not print anything on the console window!
How can I fix this?

def shut_down(s):

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

shut_down(yes)

1 Like
shut_down(yes)

If you want something to appear in the console window use print.

Also, yes should be a string.

2 Likes

@greentreemee Awesome explanation. Thanks man!!!

1 Like

def shut_down(s):

if 'yes':
    return "Shutting down"
elif 'no':
    return "Shutdown aborted"
else:
    return "sorry"

what am i doing wrong?

1 Like

In your if/elif statements, instead of just typing the string, you need to check if the argument is equal (==) to the string provided in your statements.

Review your instructions. Here’s the second instruction (#2):

Then, if the shut_down function receives an s equal to "yes", it should return "Shutting down"

Also, make sure your code is indented under your function.

2 Likes

What’s wrong with my code?
it keeps saying
Traceback (most recent call last):
File “python/cli_runner.py”, line 152, in

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

1 Like

Maybe indentation is the problem, try to format so we can see what’s the problem.
(why colon that ends if’s header looks different from other colons ? )
Note:
To learn more about formatting a code.
https://discuss.codecademy.com/t/how-do-i-format-code-in-my-posts/51139

4 Likes

Thanks.
I unconsciously used the wrong colon. And now the problem is solved.

1 Like
def shut_down(s):

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

shut_down(yes)

Any idea why this doesnt work? 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: expected an indented block (python, line 3)

1 Like

You indentation is off. Everything except the shut_down(yes) should be included within the function (as in indented so that it is not on the same level as the function).

3 Likes

Thank you very much. :smiley:

2 Likes

def shut_down(s):
return s
if s==“yes”:
return “Shutting down”
elif s==“no”:
return “shutdown aborted”
else:
return “sorry”

shut_down(“yes”)

what am I doing wrong here?

It says “Oops, try again. Your function failed on the message yes. It returned ‘yes’ when it should have returned ‘Shutting down’”.

1 Like

Look at your first line of the funtion:

def shut_down(s):
    return s

You are returning the input before anything else can happen.

3 Likes

Thanks for the comment! I delete “return s” and things work out fine. Do you get links or resources of learning more about using functions? I get confused sometimes for setting up the def and input. Thanks!

1 Like

Just search on google and any of the first page should get you sorted. That and play the more issues you solve the better your understanding and then when you read about them things will make even more sense and you’ll understand the results of your experimenting.

1 Like

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