''' Purpose: determine the length and number of vowels of a user-specified word ''' # HELPFUL CONSTANT VOWELS = 'aeiou' # In our loop, v will be 'a' then next time 'e' # then next time 'i' then next time 'o' then next time 'u' # and then the loop is done because it has reached the # end of the sequence! # get the input reply = input( 'Enter a word: ' ) # clean it up # Remove all leading and trailing whitespace using .strip()! s = reply.strip() # Call .strip() to remove leading and trailing s = s.lower() # Makes the entire string lowercase s = reply.strip().lower() # YOU CAN DO EVERYTHING AT ONCE TOO # so that you can just count the lowercase vowels in VOWELS # You could make VOWELS = 'aeiouAEIOU' but it's quicker to just # make everything lowercase! # .strip gets rid of whitespace! # " nadia " becomes "nadia" # determine and report its length n = len( s ) # determine and report the total of the number of occurrences of each of the vowels # Store each count separately in five different variables and # get the total ca = s.count( "a" ) ce = s.count( "e" ) ci = s.count( "i" ) co = s.count( "o" ) cu = s.count( "u" ) total = ca + ce + ci + co + cu # An alternate method would be to use a for loop to count! # This is an accumulator way :) # Initialize a total to 0 total = 0 for v in VOWELS: # 'aeiou' - v will change value from 'a' to 'e' to 'i' etc. c_v = s.count( v ) # This will count the # times vowel occurs # in the string for the current value of v! total = total + c_v # Take the total and keep adding # each count of the new vowel print("Length", n ) print("Vowels:", total) # You can also replace all the vowels in the original # string with "" and then count the word after that # as it would be only the remaining consonants. (this # essentially gets rid of all the vowels in the original string # and counts up the new string with just the consonants)