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 ?
5 Antworten
+ 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.
+ 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)
+ 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
0
Thanks alot
I'll try