What is the correct fix?
def factorial(n):
if n == 0:
return 1
return n * factorial(n)
- Change
factorial(n)tofactorial(n - 1) - Change the base case to
n == 1 - Change
*to+in the recursion - Remove the base case from the function
The recursive call must shrink n, otherwise it never ends.
Play Problem Solving ▸