Anti_wovel my O and o doesn't get removed


#1


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


I've almost completed this exercise but I get a slight error. When I submit the code this is the error message;
"Your function fails on antivowel("Hey look Words!"). It returns "Hy lok Words!" when it should return "Hy lk Wrds!"._"
As you can see, my functions dosen't seem to remove lowercase or uppercase letter 'o' and I don't know what to do.

Below is my code:

def anti_vowel(text):
    text_list = list(text)
    for c in "aeiouAEIOU":
        try:  
            text_list.remove(c)
        except ValueError:
            pass  # do nothing!
    result = ''.join(text_list)
    return result


#2

You should try making a list of vowels:

vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]

Then a list called anti

anti = []

then work on a look and a if/else statement


#3

Your code:

for c in "aeiouAEIOU":

only executes one time, you need to loop it for all of text_list

What your code is doing is finding ONLY the first vowel and removing that


#4

And I don't believe I've seen the "try" command before. What is that?


#5

This throws an error:

Oops, try again.
Your function fails on anti_vowel("Hey look Words!"). It returns

"['H', 'y', ' ', 'l', 'k', ' ', 'W', 'r', 'd', 's', '!']" when it should
return "Hy lk Wrds!".

It doesn't join words.


#6

return "".join(anti)

will solve the problem


#7

True, that's when I am not creating a list but empty string. Thanks.


#8

Why isn't it looping. I have used that syntax before like this:

for c in "test":
    print c
---------------------
t
e
s
t

That works just fine...


#9

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