Why isn't my code functioning correctly?!



The code will not filter the vowels from the input.

It's supposed to filter all vowels out.

def anti_vowel(text): 
    vowels = ["aeiouAEIOU"]
    final = ""
    for letter in text: 
        if letter not in vowels: 
            final = final + letter
    return final
print anti_vowel("Hi")

The last line is just for testing.


The in operator is not recursive, meaning it doesn't drill into elements. It sees this element as a string that does not match any single letter. Try using just the string without the brackets.


if letter not in vowel[0]:


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