Last active
September 1, 2015 20:25
-
-
Save diegorocha/b9e13ef1006aa95ab50a to your computer and use it in GitHub Desktop.
Multiplicação de duas listas até que seja atingido um determinado valor teto
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 | |
a = range(1, 11) | |
b = range(2, 12) | |
max = 100 | |
#Versao for | |
total = 0 | |
for x, y in zip(a, b): | |
total += x * y | |
if total >= max: | |
break | |
print 'Total: %d' % (total) | |
#Versao while | |
i, total = 0, 0 | |
termos = zip(a, b) | |
while (total < max) and (i < len(termos)): | |
x, y = termos[i] | |
total += x*y | |
i += 1 | |
print 'Total: %d' % (total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment