Skip to content

Commit ccf2770

Browse files
committed
feat: Add factorial calculation program using math.factorial
1 parent 9de1d45 commit ccf2770

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import math
2+
3+
def calculate_factorial(n: int) -> int:
4+
"""Calculate the factorial of a given number using math.factorial."""
5+
if n < 0:
6+
raise ValueError("Factorial is not defined for negative numbers.")
7+
return math.factorial(n)
8+
9+
if __name__ == "__main__":
10+
number = int(input("Enter a number to calculate its factorial: "))
11+
try:
12+
result = calculate_factorial(number)
13+
print(f"The factorial of {number} is {result}.")
14+
except ValueError as e:
15+
print(e)

0 commit comments

Comments
 (0)