Review Functions: A soloution


#1



Replace this line with your code.


#2

Hi,
Please post you code, error message, and link to the exercise for us to help you. Thanks!


#3

someone help. I wrote this code and the output is as shown below,what is the problem?
def shut_down(s):
if shut_down(s==yes):
return ("shutting down")
elif shut_down(s==no):
return ("shut_down aborted")
else
return "sorry"

File "python", line 3
return ("shutting down")
^
IndentationError: expected an indented block


#4

Hi,

Pay close attention to how if elif statements are formatted in Python. This is incorrect:

It simply should be:

if s=="yes":

And:

elif s=="no":

I'm assuming you were trying to verify that the processes were for the shut_down function, but that is unnecessary as it should be under the function definition if you indented right.

I am assuming you didn't indent everything correctly, becuase of the error message, but I can't help you with that until you format your code. Use the button in the text box to do that. Also your else statement needs a colon after it.


#5

Hi, Please help! My code below:
def shut_down(s):
return s
if s == "yes":
return "Shutting down"
elif s == "no":
return "Shutdown aborted"
else:
return "Sorry"

gives error provided below:
File "python", line 4
SyntaxError: 'return' outside function


#6

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

elif "no":
shut_down("Shutdown aborted")

else:
shut_down("Sorry")

This worked


#7

In hints we have: "Ensure your function outputs appear exactly as shown!" What does it mean by that? Is your solution such?


#8

Hi,

The line above is unnecessary and can be removed. That's the job of the if, elif statements. :slight_smile: As for the rest, make sure you have correct indents. Your code should look like this if it is indented correctly:

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

#9

The answer does not teach us everything. Please refrain from just posting answering without any explanation to the problem as that doesn't help the other users. Thank you.


#10

this returns yes and im not sure why. please assist

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


#11

The second line (return s) is making it so that when it hits the the if statement it's immediately saying s == yes instead of showing the conditon.It is returning the s argument and therefore it is equaling yes. If you do remove the (return s) you will find that it runs through the code and it'll work fine. I am a novice at this and i am not sure my explanation is the best. However, i had this problem and the fix to it was removing the second line of code. Hope this helps in some way.


#12

Hi,

Not sure why you have the first return statement like this:

When the other two are written correctly. Can you explain your thinking behind writing it like this?


#13

Thank you!! I was typing
if s("yes"):
return "Shutting down"
any reason why that didn't work?


#14

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