What's wrong with my code?


#1

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

shut_down(yes)

Whenever I test it it says:Oops, try again. Your function failed on the message yes. It returned 'Sorry' when it should have returned 'Shutting down'

What am I doing wrong?


#2

the command at the bottem uses yes as an input,
so naturally if the input is yes (if shut_down==yes:) it should return 'Shutting down'
it works as it should
consider changing the command shut_down(yes)


#3

@terawhiz95466,

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

print( shut_down('yes') )

or

yes='yes'
print( shut_down(yes) )

++++ function with 1 parameter using return-statement

def myFunction( param1 ):
    # //Begin of =myFunction= FUNCTION-BODY
    # //=myFunction= function has 1 PARAMETER param1
    # //this param1 PARAMETER is used as a -local- VARIABLE
    # //throughout the =myFunction= FUNCTION-BODY
    return param1;
    # //End of FUNCTION-BODY

You have defined a myFunction function
which takes 1 parameter param1
this param1 parameter is used
as a variable throughout the =myFunction= FUNCTION-BODY.

If you want to call/execute this myFunction function
and this myFunction function was defined
as having 1 parameter param1
you will have to provide 1 argument
in our case a "number VALUE" 4
myFunction( 4 )

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**

============================================

As you are using the return-statement in your myFunction function
you will only get a return-value no-display.
You can however capture this return-value in a variable
and then use the print-method to do a display.

theResult = myFunction( 4 )
print theResult

OR directly

print myFunction( 4 )