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

3rd Aug 2021, 2:28 AM
Shahir
Shahir - avatar
3 Antworten
+ 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
3rd Aug 2021, 2:48 AM
Abhiyantā
Abhiyantā - avatar
+ 2
Thanks
3rd Aug 2021, 3:02 AM
Shahir
Shahir - avatar
+ 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
3rd Aug 2021, 2:45 AM
Python Learner
Python Learner - avatar