Whats wrong with my code, help on review:functions


#1

def shut_down(s):
return s

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


#2

So there are a few problems with your code. You don't want to return something so quickly or it will end the function. Instead try something like this:

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

print shut_down("yes")

This program takes one argument ("s") and then checks if it is equal to a condition, like being the string "yes" or "no". I don't know if you want to include the last line, it just calls the function and passes in an argument.


#3

but why do we print at the end of the code instead of return shut_down("yes") and why do you put "yess" in the parentheses.


#4

It's another way of doing it. You could also just call the shut_down function and print inside like the following:

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

shut_down("yes")

"yes" is in parenthesis since that is what is being passed to the function. The shut_down function takes one argument (s). So in this case "yes" is being passed. If you had another statement after

shut_down("yes")

that was

shut_down("no")

then the argument (s) handles both instances