Skip to content

Instantly share code, notes, and snippets.

@renzon
Created November 27, 2018 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renzon/4bc2b3142e22f90ec605aaea9924e9c8 to your computer and use it in GitHub Desktop.
Save renzon/4bc2b3142e22f90ec605aaea9924e9c8 to your computer and use it in GitHub Desktop.
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