Skip to content

Commit 5f7321c

Browse files
authored
Update factorial function documentation and output format
1 parent 8106aea commit 5f7321c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

maths/factorial.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
"""
2-
Factorial of a positive integer -- https://en.wikipedia.org/wiki/Factorial
1+
"""Factorial of a non-negative integer.
2+
3+
For more information, see:
4+
https://en.wikipedia.org/wiki/Factorial
35
"""
46

57

@@ -29,6 +31,7 @@ def factorial(number: int) -> int:
2931
raise ValueError("factorial() only accepts integral values")
3032
if number < 0:
3133
raise ValueError("factorial() not defined for negative values")
34+
3235
value = 1
3336
for i in range(1, number + 1):
3437
value *= i
@@ -37,7 +40,9 @@ def factorial(number: int) -> int:
3740

3841
def factorial_recursive(n: int) -> int:
3942
"""
40-
Calculate the factorial of a positive integer
43+
Calculate the factorial of a non-negative integer.
44+
45+
For more information, see:
4146
https://en.wikipedia.org/wiki/Factorial
4247
4348
>>> import math
@@ -65,4 +70,4 @@ def factorial_recursive(n: int) -> int:
6570
doctest.testmod()
6671

6772
n = int(input("Enter a positive integer: ").strip() or 0)
68-
print(f"factorial{n} is {factorial(n)}")
73+
print(f"factorial({n}) is {factorial(n)}")

0 commit comments

Comments
 (0)