''' Purpose: prints total of integers from 1 to n for user-supplied n. ''' # get n reply = input( 'Enter a number: ' ) n = int( reply ) # compute total of 1 to n # We need to somehow come up with total # This concept is called accumulation total = 0 # this line is necessary because you cant add something to a value that does not exist. we call total the accumulator. for i in range( 1, n+1 ): # remember the first argument in the range is the first element in the sequence, the second argument is one greater than the final element in the sequence total = total + i # update the accumulation to include another value in the range sequence print( i, total) # see that i successively takes on the values fronm 1 to n, also see that the total is an accumulation print( total ) #for i in range( 1, n+1 ): # total = 0 + i this will ensure that total just equals i every time # print( i, total) # print total #total = n * (n+1)//2 Gauss equation #print( total )