simpliest way to create a recursive function in python code example
Example 1: recursive function in python
def factorial(x):
"""This is a recursive function
to find the factorial of an integer"""
if x == 1:
return 1
else:
result = x * factorial(x-1)
return ()
num = 3
print("The factorial of", num, "is", factorial(num))
Example 2: recursion python examples
# Recursive function factorial_recursion()
def factorial_recursion(n):
if n == 1:
return n
else:
return n*factorial_recursion(n-1)