I am attempting to understand exactly how this function works, I have been playing around with it but I am unsure.
What I know: anything with a remainder of 1 (odd number) will return 0
What I am confused about: When I calculate it I got
2which would result in but isn't '36//2 + 1' equal to '19' and not '2'?
Code:
def anon(n):
if n % 2 == 1:
return 0
else:
return 1 + anon(n//2)
print(anon(36))
1 + anon(18), not just1 + 18. The keyword you seem to be missing is "recursive".anon(36)>1+anon(18)>1+(1+anon(9))>1+1+0=2pythontutor dot comin case you want to find out yourself, I have prepared a permanent link: pythontutor.com/…