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
3 Respostas
+ 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))
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.
0
else:
return is_odd(x-1) #USE OF THIS LINE, CALL TO is_odd().....??
def is_odd(x):
return not is_even(x)