anti_vowel doesn't remove e


#1

Hey!
Why doesn't this code work for me?
It removes all letters except the first 'e':

def anti_vowel(text):
    for letter in text:
        if letter in "aeiouAEIOU":
            newstring = text.replace(letter, "")
    return newstring

It gives me the following error:
"Your function fails on anti_vowel("Hey look Words!"). It returns "Hey lk Wrds!" when it should return "Hy lk Wrds!"."

Same happens when I tried it the hard way:

def anti_vowel(text):
    newstring = text
    for letter in text:
        if letter == "a" or letter == "A" or letter == "e" or letter == "E" or letter == "u" or letter == "U" or letter == "i" or letter == "I" or letter == "o" or letter == "O":
            newstring = text.replace(letter, "")
    return newstring

#2

This won't work because of the following reasons, you define newstring here:

newstring = text.replace(letter, "")

there is nothing in newstring, what i would do is define newstring at the start of your function:

newstring = ""

if there is a hit (vowel), add an empty string to newstring, otherwise add the letter of to newstring. You can't use remove, since newstring is empty


#5

@objectninja30983 and @zeziba, posting answers without any explanation is against CC policy, please read the guidelines