8. Anti_Vowel


#1


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

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

It removes the e but not the o? I don't get what's wrong

All the vowels should be removed


`def anti_vowel(text):
    for c in text:
        if c in 'AEIOUaeiou':
            return text.replace(c,'')
            `


#2

a function ends the moment a return keyword is reached

if the return keyword is reached in a loop, the loop will break in order function to be able to end

you should use the replace action, then after the loop return the censored string


#3

I did that:

def anti_vowel(text):
    for c in text:
        if c in 'AEIOUaeiou':
           x = text.replace(c,'')
    return x

now it returns this error:
Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hey lk Wrds!" when it should return "Hy lk Wrds!".

It's the exact same thing!


#4

This is probably because strings are immutable. I think the best approach would be to store the required characters in a list as we traverse through the text, and the return the list as a string.


#5

@ellipsi, true strings are immutable, but replace() will simply create a new string.

@arcjumper41211, look at this:

 def anti_vowel(text):
    for c in text:
        if c in 'AEIOUaeiou':
           x = text.replace(c,'')
           print x
    return x
print anti_vowel("Hey look Words!")

you replace from the text string, but store the result in x. In the end, this simply means the last vowel found will be censored. You should store text


#8

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