+ 1
The code doesn't work
The code is supposed to count the number of vowels in a string and it doesn't work? x = input("Enter a string:") z = 0 y =0 for i in x: if i== 'a' or 'A': y +=1 elif i == 'e' or 'E': y +=1 elif i == 'i' or 'I': y +=1 elif i == 'o' or 'O': y +=1 elif i== 'u' or 'U': y +=1 else: z = 0 print("the output:", y)
5 Answers
+ 11
You are using `i == 'a' or 'A'`.
It's corrected form is `i == 'a' or i == 'A'` as I do below.
https://sololearn.com/compiler-playground/cgpyxr4Y3HpY/?ref=app
+ 6
It should be
if i == 'a' or i == 'A'.
An alternative is
if i in 'aA'
or much simpler
if i in 'aeiouAEIOU'.
+ 6
Infernyx ,
> your code defines / initialize a variable `z` with 0.
> in the `else` clause the value of 0 will be assigned to variable `z`.
> but this varisble is never used.
+ 2
Or turn the i to lower case and get rid of all or statements
for i in x:
i = i.lower()
if(i in "aeiou"):
y += 1
+ 1
Thank you for helping me people