Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sum the contents of a list python

# Sum the contents of a list without the builtin sum function

list = [1,2,3,4,5]
sum = 0

# loop through each position of the list and 
# add the contents of each position to the variable, sum
for i in range(len(list)):
	sum += list[i]

# result is 1 + 2 + 3 + 4 + 5 = 15
print(sum)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sum #contents #list #python
ADD COMMENT
Topic
Name
7+7 =