Need help on 8. anti vowel!


So my code is as below. I think it totally does what I want. But it is not working. Why the vowels can't filt out by my algorithm?

def anti_vowel(text):
    new_string = ""
    for n in text:
        if n != 'A' or n != 'a' or n != 'E' or n != 'e' or n != 'I' or n != 'i' or n != 'O' or n != 'o' or n != 'U' or n != 'u':
            new_string += n
            print new_string
    return new_string


The if statement is the reason it I not working. If we have "Python" as the input then the code will check for a match in every letter. Now, when it comes to our vowel "o" then it will check that if the vowel is not equal to "A", which it is not, therefore making the entire if statement true and printing it. Instead you should put the vowels in a string, and make sure it isn't in there. Like this:

if not (i in "aeiouAEIOU")

Or change the operators from or to and.


Oh yes. So I changed the "or" to "and" it worked! Thank you!


Welcome. Glad to help. :grinning:


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