Question 11
Back to Exercise
What is the output of the following Python program?
def is_even(n):
return True if n == 0 else is_odd(n - 1)
def is_odd(n):
return False if n == 0 else is_even(n - 1)
print(is_even(10), is_odd(7), is_even(3))
- A True True False Correct
- B True False False
- C False True True
- D RecursionError
Correct Answer: Option A
The calls alternate, decreasing n by 1 each time, until one function reaches 0.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!