0
Why I am getting wrong output??
a = input() j = 0 for i in a: if i != 'a' or i != 'e' or i != 'i'or i != 'o' or i != 'u': j = j+1 print(j) I have to count the no.of consonants in a string
3 Answers
+ 3
Insted of "or" ,use "and" for correct output, because for example if value if a is "apple" ,then in your case a is not equal to a it's Fasle, but you have used "or" so it will check for other conditions also which gives true, and in case of "or" ,if one condition is true then it will be True!
https://code.sololearn.com/cp3gisjz9Z8H/?ref=app
+ 2
Thanks
+ 1
Hi Shahir!
I suggest you to use and operator instead.
Because, or operator evaluates true(means 1), if any condition is satisfied.
For example,
if i != a is a true statement then your entire condition will be true even if i is equal to e or other vowels