Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Find the total of a List in Python Without sum() and with for loop in python

# Remember we can easily do this with sum() function
# But the challenge is not to use that, and use for loop
total = 0
lst = [9, 41, 12, 3, 74, 15]
for num in lst:
    total = total + num   # We can write this as (total += num)
    print(num, total)  # You can skip this print statement if you want
print('Total of all the numbers in the list:', total)

# This is the easy way
print(sum(lst))
 
PREVIOUS NEXT
Tagged: #Find #total #List #Python #Without #loop #python
ADD COMMENT
Topic
Name
6+8 =