+ 1
I need help with recursion in Python.
https://code.sololearn.com/c9S22spJfFdK/?ref=app I can't understand how this code works.
6 ответов
+ 7
Oh, I definitely remember handtracing that exact code, because why not.
https://www.sololearn.com/Discuss/1333646/?ref=app
+ 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.
+ 2
~ swim ~
Thanks for your assistance