''' Purpose: produce and print the reverse of a user-supplied word (using accummulation) ''' ### get word reply = input( "Enter word: " ) word = reply.strip() ### get a copy of the word through accumulation # Accumulator Format: # accumulator = ... # string, number, or list (depending on what we # wanna build). # Initialize accumulator to '' for string, 0 for sum/difference # and 1 for mult/division, and [] for list # for ... in sequence: # Update Accumulator looks like: # accumulator modification (accumulator = accumulator + modification) # I will be sending out an accumulator review in a few days! reversed = '' # Initialize accumulator (we will build this up) for ch in word : # word is an existing string (sequence) of characters #reversed = reversed + ch # print('when loop action continues ch =', ch, 'and reversed =', reversed) reversed = ch + reversed print( reversed ) # prints out the new version of reversed # each time we run through the loop # We started reversed off as an empty string '' and # if we have reversed = reversed + ch then # we gradually add each character to the accumulator ch # it will be '' then 'a' then 'ab' then 'abc' and build up 'abc' # reversed = ch + reversed will add the new character to # the front of each original value of reversed # Now, we will have '' then 'a' then 'ba' the 'cba' ### print reverse print( reversed )