- 1

Can someone explain this please!!

def boo(a,b): a+=2 b-=2 y=foo(a,b) return y def foo(a,b): y=(a+b)/2 return y result=boo(4,6) print(result)

22nd Nov 2016, 5:40 PM
Jacob
2 Respuestas
0
Walk through it step by step, write it down on paper if that helps. First, the function boo is called. Variable a is incremented by 2, variable b is decremented by 2, and these new values are passed into the function foo foo adds variables a and b together, divides the sum by 2, and returns that number to boo, which then returns that number to the print function
22nd Nov 2016, 5:53 PM
Erik Overberg
Erik Overberg - avatar
0
#There is defined function boo which can take two arguments to input, so when we have row with code result = boo(4, 6 ) we call it with arguments 4 and 6 #boo(4, 6) where a = 4 and b = 6 #so, then a+=2 which means a=a+2 --->a=4+2=6 #b= b-2 - - ->6-2=4 #so now a = 6 and b = 4 #That was this part of code: #def boo(a, b): # a += 2 # b -= 2 #Now we have this part: #y = foo(a, b) # return y #So, we call function foo with our a and b which means: # foo(6, 4) # y= (6 + 4) / 2 = 5.0
22nd Nov 2016, 6:12 PM
Stanislav Syarkevich
Stanislav Syarkevich - avatar