#loop_strings.py #count, sum of lengths, longest, shortest, first, last, in order, most vowels num_words = 0 sum_lengths = 0 in_order = "yes" #assume the words are entered in order #"priming read" to get first string word = input("Enter a word (Enter to quit): ").lower() #lowercase all letters longest_len = shortest_len = len(word) longest_word = shortest_word = word #the actual longest/shortest string first = last = word #in alphabetical order max_vowels = 0 max_vowel_word = word previous = word #remember the previously inputted string while word != "": #loop until empty string word_length = len(word) sum_lengths += word_length num_words += 1 if word_length > longest_len: #if this word is the longest so far, longest_len = word_length #remember its length longest_word = word #and the word itself if word_length < shortest_len: shortest_len = word_length shortest_word = word if word < first: #this word is alphabetically before the alphabetically-first so far first = word #so it is now the alphabetically-first so far if word > last: last = word #count the number of vowels this word has vowels = 0 for c in word: #each character in the word if c in ['a','e','i','o','u']: vowels += 1 if vowels > max_vowels: # a new max # vowels word max_vowels = vowels max_vowel_word = word if word < previous: #this word is alphabetically before the previously entered word in_order = "no" #thus entire sequence of words is not in alphabetical order previous = word #this word will be previous for next word #get next word: word = input("Enter a word (Enter to quit): ").lower() if num_words > 0: print("#words=",num_words, "\nTotal number of letters=", sum_lengths, "\nAverage letters per word=", sum_lengths/num_words, "\nLongest word length=", longest_len, " ", longest_word, "\nShortest word length=", shortest_len, " ", shortest_word, "\nFirst word in alphabetical order=", first, "\nLast word in alphabetical order=", last, "\nMost #vowels=", max_vowels, " ", max_vowel_word, "\nWords entered in order: ", in_order) else: print("No words entered")