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 rec(num):
2 if num <= 1:
3 return 1
4 else:
5 return num + rec(num - 1)
6
7print(rec(50))
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}
1# Recursive Factorial Example
2# input: 5
3# output: 120 (5*4*3*2*1)
4def factorial(x):
5 if x == 1:
6 return 1
7 else:
8 return (x * factorial(x-1))