''' Purpose: examine a list of words ''' # get text from user reply = input( 'Enter text: ' ) print() # split text into words words = reply.split() # 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 # hey look its an accumulator for a total... what should we initialize it to? # if we're adding to our accumulator (building a sum/total), start at 0 for w in words : # get current word's length length_of_w = len( w ) # add length to the accumulation sum_of_word_lengths = sum_of_word_lengths + length_of_w print( "w:",w ) print( "w length:", length_of_w ) print( "current sum:", sum_of_word_lengths ) print() # determine average average_word_length = sum_of_word_lengths / n # arithmetic average/mean word length print( 'Average word length:', average_word_length )