My code doesn't work! Please help!


The exercise I'm stuck at: anti_vowel


File "python", line 5
if text[t]=vowel[v]:
SyntaxError: invalid syntax


Oops, try again. Did you create a function called anti_vowel? Your code threw a "global name 'anti_vowel' is not defined" error.

def anti_vowel(text):
    for t in text:
        for v in vowel:
            if text[t]=vowel[v]:
                del text[t]
    return "".join(text)


= is how you would declare something, what is the comparator to see if something equals another?


After vowel=['a','e','i','o','u','A','E','I','O','U'], create a result variable and assign an empty string to it, like so: result = ''

Then, loop through text. For each character in the text, if the character is not in vowels, add the character to the result: result += character

Return the result.

Hope that helps.


Thanks for suggestions guys! I worked on my code and its working now!

def anti_vowel(text):
    for t in text:
        for v in vowel:
            if t==v:
    return "".join(result)


Happy for you :slight_smile:

You can also achieve the same without nested for-loop, else statement and join() method. Consider the code below.

def anti_vowel(text):
    vowels = 'aeiou'
    result = ''

    for char in text:
        if char.lower() not in vowels:
            result += char
    return result

Hope that helps.


That's great! Thanks!


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