We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f24a01b commit fa3641eCopy full SHA for fa3641e
Algorithms/Maths/Factorial/python/factorial.py
@@ -0,0 +1,21 @@
1
+num = int(input("Enter a number: "))
2
+
3
+factorial = 1
4
5
+# check if the number is negative, positive or zero
6
+if num < 0:
7
+ print("Sorry, factorial does not exist for negative numbers")
8
+elif num == 0:
9
+ print("The factorial of 0 is 1")
10
+else:
11
+ for i in range(1,num + 1):
12
+ factorial = factorial*i
13
+ print("The factorial of",num,"is",factorial)
14
15
+"""
16
+Or you can directly use the math.factorial() in python
17
18
+import math
19
20
+print ("The factorial is ",math.factorial(num), end="")
21
0 commit comments