''' Purpose: find the words of maximum length in user text ''' # get the words reply = input( 'Enter text: ' ) words = reply.split() # consider the words one by one to find a longest word longest_seen = "" # so far nothing has been seen for word in words : # consider each word in turn nw = len( word ) # get its length nl = len( longest_seen ) # get the length of the longest seen so far if ( nl <= nw ) : # compare the two lengths longest_seen = word # if current word is longer, update longest seen # At this point, we have the longest word in longest_seen. nl = len( longest_seen ) # determine the words of longest length list_words_with_longest_length = [] # We will add the longest words to this list for word in words: # Go through every word length_word = len( word ) # Get the length of each word if ( length_word == nl ): # If the word's length is the length of the longest list_words_with_longest_length.append( word ) # Add it to the list print( list_words_with_longest_length ) # In general you can have as many test expressions in # your if statement as you want so you could do # a