def counter(sentence):
a=0
e=0
i=0
o=0
u=0
for char in sentence:
if char == 'a' or 'A':
a += 1
elif char == 'e' or 'E':
e += 1
elif char == 'i' or 'I':
i += 1
elif char == 'o' or 'O':
o += 1
elif char == 'u' or 'U':
u += 1
return a, e, i, o, u
Everything looks okay to me, but when I print counter("Hello how is your day going")
it returns (27, 0, 0, 0, 0)
. 27 is the total number of characters in that sentence so it's clear that for every character the for loop goes over, it stops after the first if
condition and adds 1 to a
, but I don't know why.
Also, messed up the indentation after the function definition, don't know how to fix it, obviously it's not like that in the program.