Anti_vowel


#1

Hi, Guys.

What wrong with my code?

def anti_vowel(text):
    voweles = []
    for i in text:
        if i not in "aeiouAEIOU":
            voweles.append(i)
        return "".join(voweles)
        

print anti_vowel("Hey look Words!")

Thanks!


Anti_vowel (getting the right answer, but still showing an error message)
#2

a function ends the moment a return keyword is reached, which in your case happens in the first run of the loop. Put return at the same indention level as for loop so your whole loop can run


#4

I made the exact error for an identical solution. Check your return line :wink:

def anti_vowel(text):
    phrase = []
    for letters in text:
        if letters not in "aeiouAEIOU":
            phrase.append(letters)
    return "".join(phrase)

#6

2 posts were split to a new topic: Anti vowel


#7

Looked around for a simple solution and this was definitely the best, i took a similar route but just couldn't execute it.. Brilliant. Mine was something like..

def anti_vowel(text):
    vowels = ["A", "a", "E", "e", "I", "i", "O", "o","U", "u"]
    new = []
    for n in text:
        if n != vowels:
            new.append(n)
        else:
            print "Oops, something is wrong!"

print anti_vowel("Hey look words!")

doesn't work


#8

take a look at this code:

def anti_vowel(text):
    vowels = ["A", "a", "E", "e", "I", "i", "O", "o","U", "u"]
    new = []
    for n in text:
        print n, vowels
        if n != vowels:
            new.append(n)
        else:
            print("Oops, something is wrong!")

print anti_vowel("Hey look words!")

vowels is a list, where n is a letter. this condition will always be true. You need to loop over the vowels list. Or let python do it for you by using not in