Skip to content

Instantly share code, notes, and snippets.

@diegorocha
Last active September 1, 2015 20:25
Show Gist options
  • Save diegorocha/b9e13ef1006aa95ab50a to your computer and use it in GitHub Desktop.
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
#!/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