0
Question from python challenge
Somebody please explain me how the output for this program is odd? e = lambda x: True if x == 0 else o(x-1) o = lambda x: not e(x) print("even" if e(10//2) else "odd")
1 ответ
+ 1
e(10//2) == e(5)
e(5) => call o(4) as 5 != 0
o(4) => not e(4)
e(4) => call o(3) as 4 != 0
o(3) => not e(3)
e(3) => call o(2) as 3 != 0
o(2) => not e(2)
e(2) => call o(1) as 2 != 0
o(1) => not e(1)
e(1) => call o(0) as 1 != 0
o(0) => not e(0)
e(0) => True as 0 == 0
so, return values backwards:
e(1) == o(0) == not e(0) => False
e(2) == o(1) == not e(1) => True
e(3) == o(2) == not e(2) => False
e(4) == o(3) == not e(3) => True
e(5) == o(4) == not e(3) => False
so print("odd") as e(5) == False