(Count consonants and vowels) Write a program that prompts the user to enter a text in one line and displays the number of vowels and consonants in the text. Use a set to store the vowels A, E, I, O, and U. Sample

Respuesta :

Answer:

The program to this question as follows:

Program:

s= input("Please Enter your String : ")#input value from user in String variable  

vowel= 0 #defining integer variable

consonant= 0 #defining integer variable

for i in s: #defining for loop for count vowel and consonant

   if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'

   or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'): #if block that check vowels

       vowel = vowel + 1 #adding value in vowel variable

   else: # count consonant

       consonant = consonant + 1 #adding value in consonant variable

print("Number of Vowels: ", vowel) #print vowel

print("Number of Consonant: ", consonant) #print consonant

Output:

Please Enter your String : Database is a collection row and column

Number of Vowels:  14

Number of Consonant:  25

Explanation:

In the above python code three variable "s, vowel, and consonant" are defined, in which variable s is used to input a string value from the user end, and the "vowel and consonant" variable is used to count their values.

  • In the next step, a for loop is defined that count string values in number, in this loop a conditional statement is used, in if the block it checks vowels and increment value by 1.
  • In the else block it count consonant value and uses print function to print both variable "vowel and consonant" value      
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE