3.19. Even Numbers ¶
Write a recursive function named is_even that determines whether a
given integer is even or not. The function takes one integer value as
input which is greater than or equal to zero and returns True
if the
given number is even or returns False
if the given number is odd.
You cannot use modulo operator (``%``).
Hint: You should think what are the base conditions for the function.
Sample I/O:
>>> is_even(122)
True
>>> is_even(55)
False
>>> is_even(1)
False
>>> is_even(0)
True
def is_even(number):
if(number == 1):
return False
elif(number == 0):
return True
else:
return is_even(number-2)