8. Anti_Vowel! Please help


#1
def anti_vowel(text):
vowels = "aeiouAEIOU"
newstr = ""
for i in text: 
    if i in vowels:
        newstr = text.replace(i,"")
return newstr

I keep getting the error "Your function fails on anti_vowel("Hey look Words!"). It returns "Hey lk Wrds!" when it should return "Hy lk Wrds!"." I would really appreciate if someone could help me debug this code. Thanks in advance!


#2

def anti_vowel(text):
vowels = "aeiouAEIOU"
newstr = ""
for i in text:
if i in vowels:
newstr += ""
else:
newstr += i
return newstr
print anti_vowel("Hey You!")


#3

try vowels = ['a','e','i',o',u','A','E','I','O','U']

but I'm just the beginner

my code:
def anti_vowel(text):
return ''.join([i for i in text if i not in ['a','e','i','o','u','A','E','I','O','U']])


#4

def anti_vowel(text):
vowels = 'aeiouAEIOU'
return ''.join([i for i in text if i not in vowels])

This also works and I thought is simpler to write.


#5

is me code

def anti_vowel(text):
    string = ""
    for char in text:
        if char not in "aeiouAEIOU":
            string += char
    return string

#6

Thanks...it really helped a lot


#7
def anti_vowel(text):
want = []
dwant = []
for i in range(len(text)):
    if text[i] == "a" or text[i]== "e" or text[i]== "i" or text[i]== "o" or text[i]== "u"  or text[i] == "A" or text[i]== "E" or text[i]== "I" or text[i]== "O" or text[i]== "U":
        dwant.append(text[i])
    else:
        want.append(text[i])
print "".join(want)

My code returns the correct letters but the system keeps on sayinig it returns 'None". HELP?!


#8

I'm a noob, so may be wrong, but it looks like you didn't remember to return your 'want' variable at the end? Also, you've made it a list rather than a string. You can use dwant = "" and then later use dwant += text[i] to add as a string rather than a list


#9

It is still producing an error :frowning:


#10

I just checked your code above on mine. You can use it exactly as written, if you just change 'print' on the bottom line for 'return' :smile:


#11

Thanks! It worked like magic! :smile:


#12

:sweat_smile:

def anti_vowel(text):
    	vowel = "aeiouAEIOU"
    	char = ""
    
    	for i in text:
    		for j in range(0, len(vowel)):
    			if i == vowel[j]:
    				i = ""
    		char += i
    
    	return char