Anti_vowel


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096


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)
    lis=[]
    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":
            lis.append(n)
    return ''.join(lis)


#2

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


#3

look at this condition:

x=5
if x==5 or x==6:
    pass

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


#4

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


#5

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


#6

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.


#7

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


#8

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