recurssion python code example
Example 1: recuursion python
def recursive_method(n):
if n == 1:
return 1
else:
return n * recursive_method(n-1)
num = int(input('enter num '))
print(recursive_method(num))
Example 2: 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 3: python recursion example
def factorial(x):
if x == 1:
return 1
else:
return (x * factorial(x-1))