开发者

Need to ask user if he wants to try again (Python)

开发者 https://www.devze.com 2023-04-13 06:44 出处:网络
#Ask the user what option he wants mode = input(\"Would you like to count Vowel\'s or Consonant\'s ? (Vowel or Consonant): \")
#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")
  1. 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.

  2. Program asks for a word.

  3. Depending on mode, number of consonants or vowels are calculated and reported to the user.

  4. Program asks if another word is available. If so, steps 2 through 4 are repeated, otherwise continue to step 5.

  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
0

精彩评论

暂无评论...
验证码 换一张
取 消