How do I sum up the values stored in the list: pairs?

Asked

Viewed 33 times

-1

matriz = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
pares = [] 
for linha in range(0, 3):
    for coluna in range(0, 3):
    matriz[linha][coluna] = int(input("Digite um valor para [{}, {}]: ".format(linha, coluna)))
    if matriz[linha][coluna] % 2 == 0:
        pares.append(matriz[linha][coluna])
  • 1

    Please better your question. And put the code inside the code tag (Ctrl+K)

1 answer

0


Use the function sum.

soma = sum(pares)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.