how to print vowels and consonants and spaces are not counted
def is_vowel(letter):
vowels = 'auoei'
return letter.lower() in vowels
def is_consonant(letter):
consonants = "bcdfghjklmnpqrstvwxyz"
return letter.lower() in consonants
def vowels_consonants(line):
sentence = ''.join(line.split())
vowels = ''
consonants = ''
for letter in sentence:
if is_vowel(letter):
vowels += letter
elif is_consonant(letter):
consonants += letter
print(f'Vowels:\ncount = {len(vowels)}\nstring = {vowels}\n')
print(f'Consonants:\ncount = {len(consonants)}\nstring = {consonants}')
test_string = 'ghsdysdgfkdkil234 fmvdfvlkf2d oiopv4iagywegd'
vowels_consonants(test_string)
Comments
Leave a comment