Discussion about this post

User's avatar
Adi's avatar

sentence = "How many vowels and consonants are in this sentence?"

list = ['a','e','i','o','u']

vowels = 0

constant = 0

for letter in sentence:

if letter in list:

vowels += 1

elif letter.isalpha():

constant += 1

print(f"The number of vowels in list are {vowels} ")

print(f"The number of constant in list are {constant} ")

Vinod VV's avatar

def count_vowels_consonants(text):

vowels = "aeiouAEIOU"

vowels_count = 0

consonants_count = 0

for char in text:

if char in vowels:

vowels_count += 1

elif char.isalpha():

consonants_count += 1

return vowels_count, consonants_count

text = input(f"Enter text or sentence to find number of vowels and consonants: ")

vowels_count, consonants_count = count_vowels_consonants(text)

print(f"The number of vowels in the string is: {vowels_count}")

print(f"The number of consonants in the string is: {consonants_count}")

9 more comments...

No posts

Ready for more?