Question 1
Back to Exercise
The program below stops with an error. Which statement correctly describes the problem?
def factorial(n):
return n * factorial(n - 1)
print(factorial(5))
- A It prints 120
- B RecursionError: there is no base case, so the calls continue past 0 into negative numbers until the depth limit; add if n <= 1: return 1 Correct
- C It prints 0
- D TypeError
Correct Answer: Option B
Every recursive function needs a case that returns without recursing.
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!