0
Can someone please help me explain this code.
x = 5 def fun(x): x = x - (x-2) return x print(fun(fun(fun(x-1)))) Three questions: Is this a form of recursion? On line 5. Does the amount of â(fun)â make any difference? Because no matter how many âfunâ I put I get the same output which is 2 Does the code end after going through function the 1st time or does it end after the 3rd time (because there are 3 funâs)?
1 RĂ©ponse
+ 2
x-(x-2) = 2
Therefore fun() will always return the value 2.
The function is called three times. The first time with 4 (x-1), the other times with 2.