1def rec(num):
2 if num <= 1:
3 return 1
4 else:
5 return num + rec(num - 1)
6
7print(rec(50))
1# Reccursion in python
2def recursive_method(n):
3 if n == 1:
4 return 1
5 else:
6 return n * recursive_method(n-1)
7 # 5 * factorial_recursive(4)
8 # 5 * 4 * factorial_recursive(3)
9 # 5 * 4 * 3 * factorial_recursive(2)
10 # 5 * 4 * 3 * 2 * factorial_recursive(1)
11 # 5 * 4 * 3 * 2 * 1 = 120
12num = int(input('enter num '))
13print(recursive_method(num))
14
15
1def factorial(x):
2 """This is a recursive function
3 to find the factorial of an integer"""
4
5 if x == 1:
6 return 1
7 else:
8 result = x * factorial(x-1)
9 return ()
10
11
12num = 3
13print("The factorial of", num, "is", factorial(num))
1def yourFunction(arg):
2 #you can't just recurse over and over,
3 #you have to have an ending condition
4 if arg == 0:
5 yourFunction(arg - 1)
6
7 return arg
1# Recursive function factorial_recursion()
2
3def factorial_recursion(n):
4 if n == 1:
5 return n
6 else:
7 return n*factorial_recursion(n-1)
8
1students = { 'Alice': 98, 'Bob': 67, 'Chris': 85, 'David': 75, 'Ella': 54, 'Fiona': 35, 'Grace': 69}