8.anti_vowel


#1

Hi, I have no idea what is wrong with my code:

def anti_vowel(text):
    text = "Hello World"
    vowels = ['A', 'a', 'O', 'o', 'E', 'e', 'U', 'u', 'I', 'i']
    text1 = []
    for i in text:
        if i not in vowels:
            text1.append(i)
        else:
            pass

It's been a week since I started so I might not fully get it just yet.


#2

your else doesn't do much, you can just leave it out?

after you added all the constants to the list, you should return the string without the vowels (use: return and join())


#3

So, I changed it, and apparently it works.

def anti_vowel(text):
    text = "How does it feel? To be on your own?"
    vowels = ['A', 'a', 'O', 'o', 'E', 'e', 'U', 'u', 'I', 'i']
    text1 = []
    for i in text:
        if i not in vowels:
            text1.append(i)
    return "".join(text1)

But it doesn't let pass onto the next level, showing me the following error:
Oops, try again.
Your function fails on anti_vowel("Hey look Words!"). It returns "Hw
ds t fl? T b n yr wn?" when it should return "Hy lk Wrds!".


#4

here:

text = "How does it feel? To be on your own?"

you shouldn't overwrite the function parameter. If you want a certain string reversed at a function call and supply the string as argument


#5

Figured it out, variable 'text' wasn't needed. Thank you!


#6

you know how parameters and arguments work, right?

otherwise, here is a little reminder:

#function declaration with parameter text
def example(text):
   print text

#function call with argument for parameter
example("hello world!")

#7

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