Ask Question
27 January, 18:50

Write a Python function LetterGame () that repeatedly asks the user to input a letter. The function is to count the number of vowels the user entered. The function should stop if the user enters a digit (0-9). a) Use a while-loop and in the while loop ask the user to input a letter or to input a digit to stop. b) Check if the user entered a vowel (if command is your friend) c) If the user entered a vowel increase the counter by one d) If the user entered a digit, output the number of letters the user entered and the number and percentage of vowels among them. e) Call the function. Expected output: You entered 10 letters, 2 of which were vowels. The percentage of vowels was 20%.

+5
Answers (1)
  1. 27 January, 22:19
    0
    def LetterGame ():

    vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]

    count1 = count2 = 0

    while True:

    choice = input ("Enter a letter / digit to stop: ")

    if choice. isdigit ():

    break

    elif choice. isalpha ():

    count1 + = 1

    if choice in vowels:

    count2 + = 1

    print ("You entered " + str (count1) + " letters, " + str (count2) + " of which weere vowels.")

    print ("The percentage of vowels was " + str (count2 / count1 * 100) + "%")

    LetterGame ()

    Explanation:

    Create a function called LetterGame

    Inside the function:

    Create a list of vowels

    Initialize count1, counts the total letters, and count2, counts the vowels

    Initialize a while loop that iterates until the specified condition is met in the loop

    Get the input from the user. If it is a digit, stop the loop. If it is an alphabet, increase the count1 by 1, and also check if it is a vowel. If it is a vowel, increment the count2 by 1

    When the loop is done, print the required information

    Finally, call the function
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a Python function LetterGame () that repeatedly asks the user to input a letter. The function is to count the number of vowels the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers