Write a program that asks the user for a string of lowercase letters and numbers. The program should evaluate the string and report the number of vowels ('a', 'e', 'i', 'o', 'u') and numbers ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') in the string.

Respuesta :

Answer:

Follows are the code to this question:

def vowel(x):#defining a method vowel that accept a parameter

   return(x=='a' or x=='e' or x=='i' or x=='o' or x=='u')#return char value

def number(x):#defining a method number that accept a parameter

   return(x=='0' or x=='1' or x=='2' or x=='3' or x=='4' or x=='5' or x=='6' or x=='7' or x=='8' or x=='9')#return number value

def main():#defining main method

   s=input("Enter a string: ")#defining string variable

   v=0#defining integer variable

   n=0#defining integer variable

   for f in s:#defining for loop for count value

       if vowel(f):#defining if to check vowel

           v=v+1#count vowel value

       elif number(f):#defining elif for count number

           n=n+1#count number value

   print("Total vowels: ",v)#print vowels value

   print("Total numbers: ",n)#print numbers value

main()

Output:

Enter a string: 678qeaft

Total vowels:  2

Total numbers:  3

Explanation:

In the above program code, three methods, "vowel, number and main" is defined, in which "vowel and number" accept an x variable in its parameter and return a value with their respective name.

Inside the main method a string variable "s" is defined that accepts a string value and defines an "n and v" integer variable, and in the for loop, it calls the above methods to use the integer variable to count string and number value and print its calculated value.