PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Program to calculate factorial by recursion
# (c) Rahul Verma
#==========================================#
def fact(n):
if n == 1 or n == 0:
return 1
else:
return fact(n-1) * n
try:
num = int(input())
except:
num = 200
print("By recursion: \n" + str(fact(num)) + "\n")
# Alternative:
facto = 1
for i in range(1, num+1):
facto *= i
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run