recursion python3 code example
Example 1: python recursion example
# Recursive Factorial Example
# input: 5
# output: 120 (5*4*3*2*1)
def factorial(x):
if x == 1:
return 1
else:
return (x * factorial(x-1))
Example 2: python recursion print statement
def recursive_method(n):
if n == 1:
return 1
else:
return n * recursive_method(n-1)