xxxxxxxxxx
>>> myList = [1, 3, 5, 6, 8, 10, 34, 2, 0, 3
>>> sum(num for num in myList if not num%2)
60
xxxxxxxxxx
def sum_evens(numbers):
total = 0
for x in numbers:
if x % 2 == 0:
total += x
return total
xxxxxxxxxx
# to sum all the numbers we use python's sum() function
a = [4,5,89,5,33,2244,56]
a_total = sum(a)
xxxxxxxxxx
def list_sum(num_list):
the_sum = 0
for i in num_list:
the_sum = the_sum + i
return the_sum
print(list_sum([1, 3, 5, 7, 9]))