How to create a recursive function in 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: recursion in python
def rec(num):
if num <= 1:
return 1
else:
return num + rec(num - 1)
print(rec(50))
Example 3: recursion in python
def yourFunction(arg):
if arg == 0:
yourFunction(arg - 1)
return arg
Example 4: recursion python examples
void A(n){
if(n>1) // Anchor condition
{
return A(n-1);
}
}