''' Purpose: find the word of the longest length amongst the input ''' # get the words reply = input( "Enter a series of words: " ) words = reply.split() # need to keep track of the longest word seen so far. It's initialization # should never prevent a word of longest length being missed longest_word_seen_so_far = '' # String Accumulator (this will be set to the longest word) # Could have also set it to the first word like this: longest_word_seen_so_far = words[0] # consider the words one by one for word in words : # check the word out - compare its length to longest so far # if current word is longer than the longest word so far, need to update word_length = len( word ) guess_length = len( longest_word_seen_so_far ) if ( word_length > guess_length ): # if we find a word that has a longer length than the longest word seen so far set longest_word_seen_so_far = word # replace the longest word with the word we saw was longer # print( 'New longest word:', longest_word_seen_so_far ) # else: # this does nothing so you don't need it # pass # longest word so far must be longest as considered every word as a possibility # print longest word print( longest_word_seen_so_far )