We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9de1d45 commit ccf2770Copy full SHA for ccf2770
test.py
@@ -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