Answer to Question #176592 in Python for adhi chinna

Question #176592

Special Characters

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 stringExplanation


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.


1
Expert's answer
2021-03-30T12:09:11-0400
# Special Characters
import string

vowels = set('AEIOUY')
consonants = set(string.ascii_uppercase)
consonants -= vowels
line = input().upper()

num_vow = 0
num_cons = 0
for ch in line:
    if ch in vowels:
        num_vow += 1
    if ch in consonants:
        num_cons += 1
print(num_vow)
print(num_cons)

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
APPROVED BY CLIENTS