PLEASE HELP 8. anti_vowel


#1

def anti_vowel(text):
    vowels = ['a','A','e','E','i','I','o','O','u','U']
    NoVowels = ""
    for char in text:
        for vowel in vowels:
            if char == vowel:
                break
            else:
                NoVowels += char
    return NoVowels

here is the error:
Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "HHHHHHHHHHeeyyyyyyyyyy llllllllllooooooooooookkkkkkkkkk WWWWWWWWWWoooooorrrrrrrrrrddddddddddssssssssss!!!!!!!!!!" when it should return "Hy lk Wrds!".


#2

add a function call and a print statement:

def anti_vowel(text):
    vowels = ['a','A','e','E','i','I','o','O','u','U']
    NoVowels = ""
    for char in text:
        for vowel in vowels:
            print char, vowel
            if char == vowel:
                break
            else:
                NoVowels += char
    return NoVowels
print anti_vowel("Hey look Words!")

See how many times your loops run? It will now go through your vowel list for every character, and will add the letters many times

I would simple make vowels into a string, and then do:

if char not in vowels:

#7

what about this code?


#8

it is just an answer .


#9

Instead of a for loop inside of for loop (which as you can see can really get jumbled up), try to understand this code. It's simpler than what you have done so I assume it shall be easy for you:


def anti_vowel(text):
    text = list(text)
    mod_text = []
    for letter in text:
        if not letter in 'AaEeIiOoUu':
             mod_text.append(letter)
    return ''.join(mod_text)

Instead of making a list of vowels, I just created single string which contains all of them. Feel free to add an else statement too, to be sure that it returns that original text if that is the case.