Anti_vowel


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#


So the error message goes like my function fails on anti_vowel("Hey look Words!"). It returns "Hey lk Wrds!" when it should return "Hy lk Wrds!".
The thing is, I tried with several strings, and when I put in hey, the function would return hy, but if I put in hey look, it would return hey lk.
It seems that if the string has only one vowel, the vowel would be deleted, but if it has two or more, the first one won't be got rid of, and other vowels would disappear.
Anybody got any idea?


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


#2

yea, the way you update variable, which perfectly demonstrate by this code:

def anti_vowel(text):
    for i in text:
        if i in "aeiouAEIOU":
            new_text = text.replace(i, "")
            print new_text
    return new_text
print anti_vowel("a best fit for ur")

because text doesn't change, the last vowel removed (in your case o, in my case u) is the final result.

to overcome this problem, update text (get rid of new_text), by doing so, the string you are replacing from actually gets updated and doesn't keep all its vowels


#3

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