Created
November 2, 2019 10:58
-
-
Save MM-coder/0bbe9a3788bbf674c7f7c23bdc808810 to your computer and use it in GitHub Desktop.
Get the sum of a list without using the sum() function
This file contains hidden or 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
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