Skip to content

Commit 7d7cd3c

Browse files
Merge pull request seeditsolution#275 from Mohit5700/patch-1
Python Program for factorial of a number
2 parents 553eff1 + 597dfb8 commit 7d7cd3c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

factorial

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def factorial(n):
2+
if n < 0:
3+
return 0
4+
elif n == 0 or n == 1:
5+
return 1
6+
else:
7+
fact = 1
8+
while(n > 1):
9+
fact *= n
10+
n -= 1
11+
return fact
12+
13+
# Driver Code
14+
num = 5;
15+
print("Factorial of",num,"is",
16+
factorial(num))

0 commit comments

Comments
 (0)