-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_01.py
More file actions
42 lines (30 loc) · 771 Bytes
/
Copy pathtask_01.py
File metadata and controls
42 lines (30 loc) · 771 Bytes
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
"""
Description:
This program calculates the factorial number from an input.
Factorial of number
Usage:
"""
def factorial_calculation(n_to_calc):
"""
Gets a number and returns the factorial
1! = 1
2! = 1*2
3! = 1 * 2 * 3 = 6
4! = 1*2*3*4 =24
5! = 1*2*3*4*5 =120
:return:
"""
if n_to_calc < 0:
# negative check
n_to_calc = n_to_calc * -1
result_factorial = 1
count = 1
while count <= n_to_calc:
result_factorial = result_factorial * count
count = count + 1
return result_factorial
if __name__ == "__main__":
n_input = int(input("Enter a number:"))
result_f = factorial_calculation(n_input) # function approach here
print(f"Factorial = {result_f}")
pass