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.
2 parents 37e3501 + 34febf9 commit 8a8b483Copy full SHA for 8a8b483
Factorial!
@@ -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