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
3 ответов
+ 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.
+ 15
In Python
a = range(98,1003,2)
print (sum(a))
+ 2
Dear which language?