You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
answer=1# We start with 1 as usual for finding factorial
3
-
4
-
foriinrange(1, (number+1)): # 1 is added to second argument of range function since it in this syntax loop terminates at the second value without executing for that value.
5
-
answer=answer*i
6
-
7
-
returnanswer# answer now contains the calculated value
8
-
9
-
10
-
11
-
if__name__=='__main__':
12
-
number=input("Enter the number : ")
13
-
number=int(number)
14
-
factorial=get_factorial(number)
15
-
print("The factorial of "+number+" is = "+factorial)
16
-
1
+
2
+
#program to find the factorial of a number provided by a user
3
+
4
+
if__name__=="__main__":
5
+
number=int(raw_input("Enter a number to get its factorial: "))
6
+
factorial=1
7
+
8
+
ifnumber<0:
9
+
print("Sorry, factorial doesn't exist for negative numbers!")
10
+
elifnumber==0:
11
+
print("The factorial of 0 is 1")
12
+
else:
13
+
foriinrange(1, number+1):
14
+
factorial=factorial*i
15
+
print"The factorial of %r is %r"% (number,factorial)
0 commit comments