Skip to content

Commit 61e19a5

Browse files
Merge pull request seeditsolution#286 from mrlazyProgrammer/patch-1
Python Program to Find the Factorial of a Number
2 parents fc51376 + 216bfb6 commit 61e19a5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Factorial of a Number

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Python program to find the factorial of a number provided by the user.
2+
3+
# change the value for a different result
4+
num = 7
5+
6+
# To take input from the user
7+
#num = int(input("Enter a number: "))
8+
9+
factorial = 1
10+
11+
# check if the number is negative, positive or zero
12+
if num < 0:
13+
print("Sorry, factorial does not exist for negative numbers")
14+
elif num == 0:
15+
print("The factorial of 0 is 1")
16+
else:
17+
for i in range(1,num + 1):
18+
factorial = factorial*i
19+
print("The factorial of",num,"is",factorial)

0 commit comments

Comments
 (0)