More than one argument


The code below accepted purely by luck. Could someone please hold me by the hand as it were.
Without return (z), the console gives me "None" and it is accepted.
With return (z) and line 11 not indented I get "18" and "none" on the console..
If line 11 is not indented I get "none"on the console but no "18" and it s accepted,
I shall be very grateful

x = 5
y = 13
# Add add_function here!
def add_function(m, n):
    global x  #I gleaned this method from the internet
    global y  #from the internet
    z= m+n
    return (z)
print add_function(m,n)



I have changed the code to m=x and n = y; but even though I have"182 and "none" on the console, I get the remark "Oops, try again. add_function(-2, 0) returned 18 instead of -2", When I click submit and save again I get the remark "Oops, try again. add_function(-4, 7) returned 18 instead of 3" Iamnt sure why the values of x and y keep changing.
Thanking you.


where you get confused is how parameters and arguments works, we have our function:

def add_function(m, n):

which has 2 parameters: m and n

then, we call the function we supply arguments to satisfy the parameters:

x = 5
y = 13

def add_function(m, n):
     print m, n

print add_function(x,y)

see how the arguments are copied into the function parameters? The advantage of this is that we can call the function multiply time with different arguments (to do a repetitive task)


Thank you Stetin.That is kind. I added return (m+n) after the" print m,n) line and it worked.. Thank you


you're welcome, do you understand now? this also means, we can call the function multiply times:

x = 5
y = 13

def add_function(m, n):
     return m +n

print add_function(x,y)
print add_function(16, 8)


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