Created
January 25, 2019 19:09
-
-
Save sdelquin/f511200029deae3856226ee2b581c09a to your computer and use it in GitHub Desktop.
Factorial made in Python
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 recursive_factorial(n): | |
if n == 1: | |
return 1 | |
return n * recursive_factorial(n - 1) | |
def iterative_factorial(n): | |
result = 1 | |
for i in range(2, n+1): | |
result *= i | |
return result | |
print(iterative_factorial(4)) | |
print(recursive_factorial(4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment