''' Purpose: examine a list of words ''' # get text from user reply = input( 'Enter text: ' ) print() # split text into words words = reply.split() # list of words (reply split into list of substrings at spaces) # let's see what we got print( 'Supplied text =', reply ) print( 'words =', words ) print() # determine number of words n = len( words ) # determine total word length sum_of_word_lengths = 0 # number accumulator for w in words : # get current word's length print( 'Loop variable:', w ) len_w = len( w ) print( 'Loop variable length:', len_w ) sum_of_word_lengths = len_w + sum_of_word_lengths # modifying accumulator print( 'Sum of lengths so far (accumulator):', sum_of_word_lengths) print() # determine average average_word_length = sum_of_word_lengths / n # sum_of_word_lengths / len(words) print( 'Number of words:', n ) print( 'Average word length:', average_word_length ) # RECAP # Number Accumulator # number_accumulator = 0 (addition/subtraction) = 1 (multiplication/division) # for ... in ...: # number_accumulator = number_accumulator +/-/*// modification (number we're modifying it with) # example: # sum_of_word_lengths = 0 # for w in words: # sum_of_word_lengths = sum_of_word_lengths + len( w ) # modification is adding len(w) each time! Add the current length of the word to # the current value of the accumulator so far stored in sum_of_word_lengths (the accumulator)