''' Purpose: introduce summing accumulation ''' # get a list of numbers reply = input( 'Enter a list of numbers: ' ) slist = reply.split() print() # convert numeric text into numbers one by one nlist = [] # initialize holder to prepare for adding elements for s in slist : nbr = int( s ) nlist.append( nbr ) print( "numeric strings:", slist ) print( "integers:", nlist) print() # by accumulation get the sum of the numbers total = 0 # when you're initializing an accumulator, think about the very first run of the for loop # if you're getting a sum, start at 0 because 0 + n = n # if you're getting a product, start at 1 because 1 * n = n # string "" s + "" = s # list lst = [] lst.append( element ) -> lst = [ element ] for nbr in nlist : total = total + nbr print( "current number:", nbr ) print( "current total:", total ) print() # print summation print( "sum(", nlist, "):", total ) # there is a built in function called sum( sequence ) that will hand back the sum of a list of numbers # we do it like this to show accumulation in an easy example with many clear uses, but accumulation is # very common in computer science # when you're asked to look at a particular data type, first think about built in functions and methods that # can help you solve the problem # we don't name variables sum, max, min, print, append, or you lose the function