+ 5
Recursion
Can someone help me with this code? I'm having a hard time understanding it.. thx https://code.sololearn.com/cPdHpLVLkj0x/?ref=app
2 Respostas
+ 8
It's simple. This is how it's working.
Suppose you're checking for 4 if it's even or not.
is_even(4) will call is_odd(3) which inturn returns the 'not' of is_even(3) so basically understand it's propagation like:
(4) -> !(3) -> (2) -> !(1) -> (0)
Now when it reaches to 0, its the termination condition. Now it'll start propagating backwards like:
!False <- !True <- !False <- !True <- True
Since 0 will return True, but 1 will return 'not' of what 0 returns 'cuz of that is_odd function which returns 'not' of whatever is being returned by is_even function. Hence 1 will return False.
Lol, lot of 'return' words. Don't get confused. Think it step by step.
And similarly 2 will return 'not' of whatever returned by 1, in this case True.
1 is returning false, 2 is returning True, now it should make sense.
And similar way down to 4 which will return 'not' of 3 that is True.
0
امم