8. Anti_vowel


#1

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?


#2

What error are you getting?


#3

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


#4

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"


#5

I have this but it still doesn't work:

def anti_vowel(text):
    text=text.lower()
    result=""
    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":
            i+=1
        else:
            result=result+text[i]

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


#6

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.


#7

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):
    result=""
    for i in range(len(text)):
        if text[i] in "aeiouAEIOU":
            result=result
        else:
            result=result+text[i]
    return result

#8

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!


#9

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