Anti_vowel lesson help


Error Message:

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

Can someone review my code and tell me what I'm doing wrong?

def anti_vowel(text):
    vowels = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u']
    finalword= []
    for char in text:
        for vowel in vowels:
            if char != vowel:
    return "".join(finalword)


for vowel in vowels:

That is what is causing the massive repetition.
Think, you are taking char and comparing it against each vowel. If it doesn't match that vowel you append it to the list and with the same char compare it to the next vowel, if it doesn't match you append it again. Repeated for all vowels and all chars. This is why you still have vowels in the final output too.


Hello jagking,
I removed the else statement and it still wouldn't work.
How would I go around doing that for each char in the given text it compares every vowel in the vowels list all at once, not individually.


You can use in. It will do exactly what you want. E.g.

if something in iterable:
    #  Do this.


Finally got this working, my mistakes were on the condition "if not" and the ".append" since I was filling a string instead of a list in order to make the new word.

def anti_vowel(text):
text_new = ""
for letter in text:
if not letter in "aeiouAEIOU":
text_new += letter
return text_new

print anti_vowel("Hey Look Words!")


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