''' Purpose: determine the length and number of vowels of a user-specified word ''' # HELPFUL CONSTANT LOWER_CASE_VOWELS = 'aeiou' # defines a string -- which is a sequence of characters # get the input reply = input( 'Enter a word: ' ) # clean it up stripped = reply.strip() # remove white space word = stripped.lower() # determine and report its length n = len( word ) print( n ) print() # determine and report the total of the number of occurrences of each of the vowels # one way to do it is to have a separate line for vowel counting. a_occurrences = word.count( 'a' ) # counting number of a's e_occurrences = word.count( 'e' ) # counting number of e's i_occurrences = word.count( 'i' ) # counting number of i's o_occurrences = word.count( 'o' ) # counting number of o's u_occurrences = word.count( 'u' ) # counting number of u's total_occurrences = a_occurrences + e_occurrences + i_occurrences + o_occurrences + u_occurrences print( total_occurrences ) print() # another way to do it is with a loop that considers all of the vowels in turn. nbr_vowels = 0 # an integer accumulator -- starts off with zero # as we have not done any counting yet for v in LOWER_CASE_VOWELS : # this iterates on an individual character in a # sequence of characters making up LOWER_CASE_VOWELS current_count = word.count( v ) # word.count( v ) returns the number of occurrences # of the value of variable v in our word; i.e., # we are going to count the number of times the # current vowel in v occurs in word print( word, v, current_count ) # print out what we know nbr_vowels = nbr_vowels + current_count # need to update the accumulator with the latest # vowel count print( nbr_vowels ) # print the total number of vowels in the word