0

python functional progrAMMING OUTPUT.............??

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)) OUTPUT True False OUTPUT

6th Apr 2018, 8:33 PM
Smriti Rastogi
Smriti Rastogi - avatar
3 Answers
+ 1
https://code.sololearn.com/cy9taSlZY3eF/?ref=app def is_odd(x): return (x % 2) == 1 def is_even(x): return not is_odd(x) print(is_odd(17)) print(is_even(23))
6th Apr 2018, 8:40 PM
Emma
0
Working code: def is_even(num): return num % 2 == 0 def is_odd(num): return num % 2 != 0 print(is_odd(17)) print(is_even(23)) How it works Both functions get the reminder of the number given after division by 2. Then it checks if the reminder is 0 or not, if it's 0 that means the number is even if it's not 0 then the number is odd.
6th Apr 2018, 8:38 PM
TurtleShell
TurtleShell - avatar
0
else: return is_odd(x-1) #USE OF THIS LINE, CALL TO is_odd().....?? def is_odd(x): return not is_even(x)
7th Apr 2018, 2:12 PM
Smriti Rastogi
Smriti Rastogi - avatar