Answer to Question #268780 in Python for Sasi

Question #268780

Count the vowels and consonants in string without including spaces.

1
Expert's answer
2021-11-19T14:39:29-0500
str=input("Please enter a string as you wish: ");
vowels=0
consonants=0
for i in str:
    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' ):
           vowels=vowels+1;#vowel counter is incremented by 1
    elif i == ' ':
        consonants=consonants;
    else:
        consonants = consonants + 1;
#consonant counter is incremented by 1
print("The number of vowels:",vowels);
print("\nThe number of consonant:",consonants);


Please enter a string as you wish: I am a boy
The number of vowels: 4

The number of consonant: 3

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