Last active
August 29, 2015 14:17
-
-
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)
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
#!/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