How do I sum up the values ā€‹ā€‹that are in a list? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How do I sum up the values ā€‹ā€‹that are in a list?

Is a large list, with range of (98, 1003, 2), obviously only prints the even numbers that are in that range, my question is ... how do I add all the values ā€‹ā€‹of the list, I mean 98 + 100 + 102 + 104 ...... + 1002

17th Apr 2018, 10:10 AM
Bryan28
Bryan28 - avatar
3 Respostas
+ 3
For any language you can use a loop to traverse the list and then add each value to a variable, maybe name the variable sum. Before the loop sum should be initialized to 0. In Pyrhon there is the method sum(list) that returns the sum of the elements of a list.
17th Apr 2018, 10:23 AM
cyk
cyk - avatar
+ 15
In Python a = range(98,1003,2) print (sum(a))
17th Apr 2018, 10:23 AM
šŸŒ›DTšŸŒœ
šŸŒ›DTšŸŒœ - avatar
+ 2
Dear which language?
17th Apr 2018, 10:19 AM
Chukwuebuka Onyekelu