Skip to content

Instantly share code, notes, and snippets.

@diegorocha
Last active August 29, 2015 14:17
Show Gist options
  • Save diegorocha/d3737ba3c5d5fd272989 to your computer and use it in GitHub Desktop.
Save diegorocha/d3737ba3c5d5fd272989 to your computer and use it in GitHub Desktop.
Conversão da função teste de recursiva para interativa com o objetivo de não estourar o limite de recursão. (Dúvida da lista Python Brasil. Adaptado para pep8)
#!/usr/bin/env python
def teste(n, x=0):
if n == 0:
print n
print "--------------------------------------------"
print x
else:
print n
x = n + x
return teste(n-1, x)
def teste_loop(n, x=0):
while n != 0:
print n
x = n + x
n -= 1
print n
print "--------------------------------------------"
print x
teste(9)
teste_loop(9)
teste_loop(42000)
teste(42000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment