0

Vowel counter

text =" enter the text " vowels = "aeiouAEIOU" count = 0 for char in range(len(text)): if char in vowels: count += 1 print(count) What is the wrong ?

8th Jun 2025, 9:36 PM
Eng : Abeer Mohamed Hassan Taha
Eng : Abeer Mohamed Hassan Taha - avatar
5 Réponses
+ 4
or this text =" enter the text " vowels = "aeiouAEIOU" count = 0 for char in text: if char in vowels: count += 1 print(count) explanation: for char in range(len(text)) char = 0, 1, 2, 3... so you have to use text[char] to actually get the letters. text[0] = 'e' text[1] = 'n' ... it's more like the C -style iteration. for char in text char = 'e', 'n', 't', 'e', 'r'... you iterate the letters directly. it's the more Pythonic way of iterating the characters in the string.
9th Jun 2025, 12:49 AM
Bob_Li
Bob_Li - avatar
+ 2
Eng : Abeer Mohamed Hassan Taha > You are forgetting that char is a number thus text[char] in the if condition > You indented the print(count) so every vowel counted and printed the count text =" enter the text " vowels = "aeiouAEIOU" count = 0 for char in range(len(text)): if text[char] in vowels: count += 1 print(count)
8th Jun 2025, 10:09 PM
BroFar
BroFar - avatar
+ 1
text =input("Enter your text") vowels = "aeiouAEIOU" count = 0 for char in range(len(text)): if text[char] in vowels: count += 1 print("the total of vowel letters are : ",count) works very well Thanks alot
10th Jun 2025, 12:31 AM
Eng : Abeer Mohamed Hassan Taha
Eng : Abeer Mohamed Hassan Taha - avatar
0
Thanks alot I'll try
9th Jun 2025, 4:30 AM
Eng : Abeer Mohamed Hassan Taha
Eng : Abeer Mohamed Hassan Taha - avatar