+ 1

Kindly explain how this code rrun

def is_even(x): if x == 0: return True else: return is_odd(x-1) def is_odd(x): return not is_even(x) print(is_odd(17)) print(is_even(23))

8th Mar 2017, 4:31 PM
ANAS
ANAS - avatar
1 Answer
+ 2
A number is even if and only if that number-1 is odd. The program works for positive integers only (including 0).
8th Mar 2017, 5:32 PM
Álvaro