+ 1

I need help with recursion in Python.

https://code.sololearn.com/c9S22spJfFdK/?ref=app I can't understand how this code works.

20th Apr 2019, 4:40 AM
Abdul S Ansari
Abdul S Ansari - avatar
6 Respuestas
+ 7
Oh, I definitely remember handtracing that exact code, because why not. https://www.sololearn.com/Discuss/1333646/?ref=app
20th Apr 2019, 4:54 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
~ swim ~ Understood Please check me Let assume x = 2 is_odd(2) #returns = not is_even(2) -> is_even(2) #returns = is_odd(2-1) -> is_odd(1) #returns = not is_even(1) -> is_even(1) #returns = is_odd(1-1) -> is_odd(0) #returns = not is even(0) -> is_even(0) #returns = True So in this whole process 'not' has come 3 times. not True == False not False == True not True == False 'False' is printed. ~~~~~~~~AND~~~~~~~~ is_even(2) #returns = is_odd(2-1) -> is_odd(1) #returns = not is_even(1) -> is_even(1) #returns = is_odd(1-1) -> is_odd(0) #returns = not is_even(0) -> is_even(0) #returns = True So in this whole process 'not' has come 2 times. not True == False not False == True 'True' is printed.
29th Apr 2019, 3:51 PM
Abdul S Ansari
Abdul S Ansari - avatar
+ 2
~ swim ~ Thanks for your assistance
29th Apr 2019, 4:00 PM
Abdul S Ansari
Abdul S Ansari - avatar