Answer to Question #167913 in Python for srikanth

Question #167913
Write a program to count Vowels and Consonants in string.
Input

The input will be a single line containing a string s.
Output

The first line of output should contain no of Vowels in the given string
The second line of output should  contain no of Consonants in the given string
Explanation

For example, if the given string is "Good Morning"
Vowels in the string "Good Morning" are "o, i" and their count is 4.
Remaining characters in the string are consonants their count is 7.
The First line of output is 4\nThe second line of output is 7.
Sample Input 1
Good Morning
Sample Output 1
4
7

Sample Input 2
welcome
Sample Output 2
3
4
1
Expert's answer
2021-03-04T10:46:35-0500
#The input will be a single line containing a string s.
inputString=input("Enter string: ")
vowels=0
consonants=0
inputString=inputString.lower()
for l in inputString:
    #check if the letter of the string is vowel
    if(l == 'a' or l == 'e' or l == 'i' or l == 'o' or l == 'u' ):
        vowels+=1
    else:
        #check if the letter of the string is consonant
        if l != ' ' and l.isdigit()==False:
            consonants+=1
#The first line of output should contain no of Vowels in the given string
print("Vowels: "+str(vowels))
#The second line of output should  contain no of Consonants in the given string
print("Consonants: "+str(consonants))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS