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