My code throws the error message "Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "" when it should return "Hy lk Wrds!"."

I'm expecting the code to go over the entire text and replace the vowels with an empty string, which should theoretically give the correct output for whatever is put into it.

Here's my code:

def anti_vowel(text):
    vowels = "AEIOUaeiou"
    result = ""
    for char in text:
        if char in vowels:
            text.replace(char, "")
    return result

I think I'm just using the str.replace() function wrong.


Where does result get its value from? Your code returns an empty string.


Instead of replacing anything, add char to result if char is not in vowels =)

What your code is doing is trying to replace something in text, instead of making anything out of your String-variable "result"

vowels = "aeiouAEIOU"

def anti_vowel(text):
    new_string = ""
    for i in text:
        if not i in vowels:
            new_string += i  
    return new_string
print anti_vowel("abcdefg")


Ah, glaring mistake there. Thank you for pointing that out.

@microresistor thank you as well, that method is much more straightforward to understand for me.

I finally got it, thanks you guys!


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