8. Anti_vowel


My code:

def anti_vowel(text):
result = ""
text = str(text)
for c in text:
if c != "aeiouAEIOU":
result = result + str(c)

return result

any help?


What error are you getting?


it dosn`t mean c not in "aeiouAEIOU", it means c is not equal "aeiouAEIOU"


You need to change the line that says "if c != "aeiouAEIOU":" Essentially, you are asking it to compare each letter to "aeiouAEIOU", instead of checking to see if c is in "aeiouAEIOU"


I have this but it still doesn't work:

def anti_vowel(text):
    for i in range(len(text)-1):
        if text[i]=="a" or text[i]=="i" or text[i]=="e" or text[i]=="o" or text[i]=="u":

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


You're not returning anything.

You also need to account for the capitals, AEIOU. But it makes your if statement unnecessarily long.
Why not just put
if text[i] in "aeiouAEIOU"?
You also don't need that i+=1 as the for loop will go through every i anyways.


I wasn't aware you could check for one letter in a string itself. Must have missed that in the lessons :frowning:
Thanks, that was helpful. Works now: I modified it to:

def anti_vowel(text):
    for i in range(len(text)):
        if text[i] in "aeiouAEIOU":
    return result


This was my solution:

def anti_vowel(text):
    new_text = ""
    vowel = ['a','e','i','o','u']
    for char in text:
        if char.lower() not in vowel:
            new_text += char
    return new_text

Hope it helps!


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