How to write a recursive function in Python?
How to write a recursive function in Python?
How to write a recursive function in Python?
solveurit24@gmail.com Changed status to publish February 13, 2025
A function that calls itself until a base case is met.
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
print(factorial(5)) # Output: 120solveurit24@gmail.com Changed status to publish February 13, 2025