Created
November 27, 2018 14:34
-
-
Save renzon/4bc2b3142e22f90ec605aaea9924e9c8 to your computer and use it in GitHub Desktop.
This file contains 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 fat(n): | |
i = 1 | |
result = 1 | |
def fat_iter(): | |
nonlocal i, result | |
if i > n: | |
return | |
result *= i | |
i += 1 | |
fat_iter() | |
fat_iter() | |
return result | |
def test(): | |
assert 1 == fat(0) | |
assert 1 == fat(1) | |
assert 2 == fat(2) | |
assert 6 == fat(3) | |
assert 24 == fat(4) | |
assert 120 == fat(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment