Why this code doesn't work?

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

The following is my code:

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 == vowels:
            NoVowels += char
    return NoVowels

Please help me!


if char == vowels:
What is vowels? vowels = ['a','A','e','E','i','I','o','O','u','U']
What will char be? A Single character. Can a single character ever equal a whole list? I'm guessing this was a typo.


Here is my solution if it helps you:

def anti_vowel(text): #defines a function
together = "" #assigns empty string to together
for c in text: #for every character in text do something
if c not in "aeiouAEIOU": #checks if c is not a vowel
together = together + c #adds characters together so return statment returns whole string in one line
return together #returns text without vowels

I'm still a beginner too so if you are more experienced and you see any mistakes in my code feel free to correct me,


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