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 "Hey lk Wrds!" when it should return "Hy lk Wrds!".


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


#2

so we have our string:

Hey look Words!

which is stored in a variable x, agree?

then we loop over string, then e is encountered and e is replaced with '', the result of this replace action is stored in n_t. x still contains the original string (Hey look Words!)

then o is encountered, we do replace again. But here is a problem. You replace all o's with ''. but the replacement is done on x (which contains the original string, still containing e) and stored in n_t

because you execute replace on x, only the last replacements stands (last vowel of the string stored in x)


#3

OK, now i replaced it with this code:

def anti_vowel(text):
    n_t = ''       
    for x in text:
        if x == 'a' or x == 'e' or x == 'i'\
        or x == 'o' or x == 'u' or x == 'A'\
        or x == 'E' or x == 'O' or x == 'U'\
        or x == 'I':
            
            n_t  += text(x)
        
    return n_t

then its throw this error:

Does your anti_vowel function take exactly one argument (a string)? Your code threw a "'str' object is not callable" error.


#4

Does this mean its return more than ONE argument ?


#5

x contains the characters of your string, so you can just do n_t += x

it seems now your code does the exact opposite of what it should do, this gives a list of vowels


#6

thank you so much i did it


#7

using text(x) made text a function call with argument x, but text is not a function, so not callable (that explains the error)

Good that you solved it :slight_smile:


#8

thank u
all was needed is else XD


#9