Anti-vowel problem


#1



I am working on the anti-vowel exercise and using the code I am receiving an error message. The letter 'e' doesn't seem to be recognised, even though I have included it in the vowel list.

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

Your function fails on anti_vowel("Hey look Words!"). It returns "Hey lk Wrds!" when it should return "Hy lk Wrds!".


 def anti_vowel(text): 
    newstr=""
    vowels = ('a','e','i','o','u','A','E','I','O','U')
    for x in text: 
        if x in vowels: 
            newstr = text.replace(x,"")
    return newstr


#2

look at this code:

def anti_vowel(text): 
    newstr=""
    vowels = ('a','e','i','o','u','A','E','I','O','U')
    for x in text: 
        if x in vowels: 
            newstr = text.replace(x,"")
            print newstr
    return newstr
print anti_vowel("a bee in you")

its your code, with a additional print statement and a function call

Take a close look at the output. So we have the string we want to censor (lets call it original string), you replace constantly from the original string, and store it in a new variable.

But because you keep replacing from the original string, only the last replace statement persist.

If you want to do this, store the replacement in the same variable as you are replacing from


#3

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