Anti_vowels


#1



Why this code doesn't work?

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#


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


Please help me!


#2

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.


#3

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,


#4

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