Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hey look Words!" when it should return "Hy lk Wrds!".

Can anyone explain me what is the mistake in my code, please?

def anti_vowel(text):
    texti = str(text)
    for n in texti:
        if n != "a" or "e" or "i" or "u" or "o" or "A" or "E" or "I" or "U" or "O":
    return ''.join(lis)


This about your boolean if statement. At the moment it will always be True.


look at this condition:

if x==5 or x==6:

see how i do comparison at both sides of the or operator? You need to do the same, check if n != 'a' or n != 'b' and so on, otherwise it will just evaluate the strings to true, and your if condition will always be true


Still not working... I replaced the (n != 'a' or n != 'b') code with not in "aeiouAEIOU" and worked like a charm :slight_smile:. I think it is not possible to solve the problem with this kind of code


you would have to replace them all, then it work, but not in is much more efficient.

@jagking is right, or will indeed not work


or was the wrong one to use. Think about it, n is one character, let us say it was "a". It would be False on n != "a" but because it is an or, it will be True on every other check and so because it is True on even one it will return True. and should have been used. You, of course, found a more efficient way, so it's a bit redundant but just so you was aware.


I tested using and instead of or and worked fine. Thanks


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.