0

Vowels-consonant-counter needs revision

I recently wrote a code to enter a text and it counts the vowels and the consonants and outputs them, take a look at my code: https://code.sololearn.com/cvxqT7VnBEVN/?ref=app I think my functions „count_vowels()“ and especially „count_consonant()“ are way to long. Does anyone have an idea to write the function shorter?

10th Sep 2021, 12:00 AM
Dude
Dude - avatar
1 Respuesta
+ 1
Hi Dude! Of course, you can for loop to avoid repeating processes. Here it is what I mentioned above def count_vowels(): number_of_vow = 0 for i in text: if i.lower() in "aeiou": number_of_vow += 1 return number_of_vow def count_consonants(): number_of_cons = 0 for j in text: if j.lower() in "bcdfghjklmnpqrstvwxyz": number_of_cons += 1 return number_of_cons text = input("Enter your text:\n>") print(f"You got {count_consonants()} consonants and {count_vowels()} vowels in your text.")
10th Sep 2021, 2:25 AM
Python Learner
Python Learner - avatar