#Ask the user what option he wants
mode = input("Would you like to count Vowel's or Consonant's ? (Vowel or Consonant): ")
mode = mode.strip()
mode = mode.lower()
# Tell the user the input he entered wasn't valid
while mode != 'consonant' and mode != 'vowel':
mode = input("That's not correct. Would you like to count Vowel's or Consonant's ? (Vowel or Consonant): ")
#get the word from the user
word = input("Please enter your Word: ")
vowel_count = 0
consonant_count = 0
for letter in word:
if letter in 'aeiouAEIOU':
vowel_count += 1
for letter in word:
if letter in 'bcdfghjklmnpqrstvwxyzBCDF开发者_如何学JAVAGHJKLMNPQRSTVWXYZ':
consonant_count += 1
if mode == "consonant":
print(word,"contains", consonant_count, "consonant's")
if mode == "vowel":
print(word,"contains", vowel_count, "vowel's")
Program Starts and asks the user whether they want to count vowels or consonants, this is stored as a "mode". If user provides input other than "consonant" or "vowel", program interprets this as an error and re-asks for input.
Program asks for a word.
Depending on mode, number of consonants or vowels are calculated and reported to the user.
Program asks if another word is available. If so, steps 2 through 4 are repeated, otherwise continue to step 5.
Depending on mode, average vowels per word or average consonants per word are reported to the user.
Im stuck on step 4 i don't know how to ask the other for another word and repeat the same process
while c:
do_stuff()
c = raw_input('Do you want to contine y/n')
if c.lower().startswith('y'):
c = True
else:
c = False
精彩评论