I’m super new to Python and trying to make a factorial function using recursion. But it just keeps crashing with some RecursionError.
Here’s my code:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n)
print(factorial(5))
I thought “if n == 0” would stop it, but nope.
Can someone explain why it’s not stopping and how I can fix it so factorial(5) gives 120?