We have to write a python program to read through a pre-set list and find the sum. No matter what i do it never works. The code i currently have is:
number_list = [425, 576, 945, 1086, 15]
print("There is a list of numbers as follows:")
for items in number_list:
print(items)
total =sum(items)
print("the sum of the numbers in the list is: ", total)
>Solution :
You need to pass to the sum() function the name of the list that you want to find the sum of its elements, not the items variable, which only contains the value of the last item:
number_list = [425, 576, 945, 1086, 15]
print("There is a list of numbers as follows:")
for items in number_list:
print(items)
total = sum(number_list)
print("the sum of the numbers in the list is: ", total)