''' 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 # this is called an accumulator # it starts at zero because we haven't added anything yet total = 0 for number in range( 0, n+1 ): # total = 0; we have to set the accumulator before the loop # or it makes total equal to the last number total = total + number print(number, total) print() # print total print( total )