recursive python function 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: recursion in python
def rec(num):
if num <= 1:
return 1
else:
return num + rec(num - 1)
print(rec(50))
Example 3: recursion python examples
def factorial_recursion(n):
if n == 1:
return n
else:
return n*factorial_recursion(n-1)
Example 4: recursion in python
def yourFunction(arg):
if arg == 0:
yourFunction(arg - 1)
return arg