Created
March 19, 2022 21:09
-
-
Save Eligijus112/007db74379e66fcbd475363b4fa9540e to your computer and use it in GitHub Desktop.
Factorial of n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def factorial(n: int) -> float: | |
| """ | |
| Given a positive integer, calculate its factorial | |
| """ | |
| if not isinstance(n, int): | |
| raise TypeError('n must be an integer') | |
| if n < 0: | |
| raise ValueError("n must be positive") | |
| if n == 0: | |
| return 1 | |
| return n * factorial(n - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment