recursive function example in python
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: recursion in python
def yourFunction(arg):
if arg == 0:
yourFunction(arg - 1)
return arg
Example 3: 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))