-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactorial.py
More file actions
62 lines (54 loc) · 1.66 KB
/
Factorial.py
File metadata and controls
62 lines (54 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def factorial(num):
result = 1
for i in range(num):
result=result * (i+1)
return result
user_input = input("Enter the number to find factorial: ")
factorial_of_user_input = factorial(user_input)
print(factorial_of_user_input)
##********************************************
##Programming logic:
##The factorial of a number is the product of all the integers from 1 to that number.
##factorial of n is n!
##5! = 5*4*3*2*1 =120
##Factorial is not defined for negative numbers
##And the factorial of zero is one, 0! = 1.
##********************************************
##Program Explaination:
##
##1.defining functio for factorial
##2.declaring result variable as 1 in initial
##and this result variable will be used to store
##the output factorial value.
##3.By using for loop we are iterating num value(ie, user input as parameter)
##4. result =result *(i+1) (ie, iterating user input
## and multiplying by result variable
## and storing in result and for next iteration
## it will multiply by updated result variable with i upto n number)
##
##********************************************
##Test cases:
##
##case 1:
## I/P:
## Enter the number to find factorial: 5
## O/p:
## 120
##
##case 2:
## I/P:
## Enter the number to find factorial: 0
## O/p:
## 1
##
##case 3:
## I/P:
## Enter the number to find factorial: 1
## O/p:
## 1
##case 4:
## I/P:
## Enter the number to find factorial: 7
## O/p:
## 5040
##********************************************