0

Could you please explain me this concept step by step?

def fun(a): x=a**2 y=0 while x>1: x=x-1 y+=2 return y print (fun (1)+fun(2))

15th May 2020, 3:35 PM
Bhanu Tripathi
Bhanu Tripathi - avatar
1 Answer
+ 2
For func(1) x=1**2 x=1 y=0 While x>1 is false So return Y func(1) returns 0 For func(2) x=2**2 x=4 y=0 While x>1: x=4-1=3 y=y+2=2 while 3>1: x=3-1=2 y=y+2=2+2=4 while 2>1: x=2-1=1 y=4+2=6 Now while x>1 is false so y is returned fun(2) returns 6 print(fun(1)+fun(2)) Prints 0+6=6
15th May 2020, 3:42 PM
Abhay
Abhay - avatar