recursion problem in python code example
Example 1: recursion in python
def rec(num):
if num <= 1:
return 1
else:
return num + rec(num - 1)
print(rec(50))
Example 2: 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))