Skip to content

Commit 35ef604

Browse files
Add recursive factorial implementation in Python
1 parent e2a78d4 commit 35ef604

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

factorial_recursive.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def factorial(n: int) -> int:
2+
"""Return factorial of a given number n using recursion."""
3+
if n == 0 or n == 1:
4+
return 1
5+
return n * factorial(n - 1)
6+
7+
8+
if __name__ == "__main__":
9+
print(factorial(5)) # Output: 120

0 commit comments

Comments
 (0)