Skip to content

Instantly share code, notes, and snippets.

@Eligijus112
Created March 19, 2022 21:09
Show Gist options
  • Save Eligijus112/007db74379e66fcbd475363b4fa9540e to your computer and use it in GitHub Desktop.
Save Eligijus112/007db74379e66fcbd475363b4fa9540e to your computer and use it in GitHub Desktop.
Factorial of n
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