8. anti_vowel: What's wrong with my code


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2

My function fails on anti_vowel("Hey look Words!"). It returns "Hey look Words!" when it should return "Hy lk Wrds!".
I'm unable to find error in my code. Can anyone please help me?


def anti_vowel(text) :
    b = ""
    l = 0
    while l<len(text):
        if text[l] != "A" or text[l] != "E" or text[l] != "I" or text[l] != "O" or text[l] != "U" or text[l] != "a" or text[l] !=  "e" or text[l] != "i" or text[l] != "o" or text[l] != "u" :
            b+=text[l]
        l+=1
    return b


#2

It's the way that OR works that is the cause. It yields True unless the first letter it tests is "A", and consequently never sees the rest of the logical expression and adds the character to the output string.

OR is said to short circuit on the first True.

A = True
B = False
C = False
D = False

if A or B or C or D: print True    # True

In the above expression, B, C, and D are never examined.

While your method is rather long and convoluted, it would work if it used and instead of or.

if A and B and C and D: print True
else: print False

# False