Anti_vowel


#1



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


The message says "Did you create a function called anti_vowel? Your code threw a "global name 'a' is not defined" error." I don't understand why this message shows up, since I have created the function. Can anyone help me out here?


def anti_vowel(text):
    textn=text.lower()
    length=len(text)
    vowels=[a,e,i,o,u]
    for i in range (0,length):
        for x in vowels:
            if x==textn[i]:
                text.remove(text[i])
        return text


#2

I'm no professional, but I'd say you have to use ['a', 'e', ...] when you define vowels


#3

@tudoumimosa your list of vowels should have quotation marks around each letter because each of them is supposed to be a string. If your code doesn't work after that, then try mine:

def anti_vowel(text):
    word = '' 
    for letter in text:
        if not (letter in 'aeiouAEIOU'):
            word += letter
    return word

#4

Your code is much better. Thank you!


#5

Welcome! Glad to help!:slight_smile:


#6

hi
could you please let me know why this code does not work for all the cases


#7

Psst.
Want a concise method?

def anti_vowel(text):
    word = filter(lambda i: i not in "aeiouAEIOU", text)
    return word

You'll understand when you get to the "Advanced Topics in Python" section
:grinning:


#8

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