Skip to content

Instantly share code, notes, and snippets.

@MM-coder
Created November 2, 2019 10:58
Show Gist options
  • Save MM-coder/0bbe9a3788bbf674c7f7c23bdc808810 to your computer and use it in GitHub Desktop.
Save MM-coder/0bbe9a3788bbf674c7f7c23bdc808810 to your computer and use it in GitHub Desktop.
Get the sum of a list without using the sum() function
a = [5,9,19,0,3,-45,7,3,-20]
b = [-19,2,3,-8,3.5,18.9, 24]
def soma(lista: list):
soma = 0
for i in lista:
soma += 1
return soma
print("A soma da lista a e: " + str(soma(a)))
print("A soma da lista b e: " + str(soma(b)))
if soma(a) > soma(b):
print("A soma da lista a e maior do que o da lista b")
elif soma(a) < soma(b):
print("A soma da lista b e maior do que o da lista a")
else:
print("As somas das listas a e b sao iguais")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment