8. Anti-Vowel


#1

Hi folks,

i write this code outside of codecademy, and it passed (Ie. it prints the string without vowels). I am getting the following error when I type it in here, despite the fact that it also works here. Any ideas? Somehow I neglected to see that I hadn't returned the calculation... Off to bed I go.

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

def anti_vowel(text):
    less = ""
    vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]
    for i in text:
        if i not in vowels:
            less = less + i
    print less
    **return less**
anti_vowel("Hiya dear friend")

#2

I have some magic for you!

class WordWizard:
    
    def __init__(self):
        self.name = "Word Wizard"
        
    def _remove_vowels_spell(self, word):
        return ''.join([letter for letter in word if letter.lower() not in 'aeiou'])
        
    def _cast_spell(self, *spell):
        words = []
        for word in spell:
            words.append(self._remove_vowels_spell(word))
        return words
    
    def __call__(self, *args, **kwargs):
        print("I will change your words! For the better of course. See: ",*self._cast_spell(*args))
    
    def __str__(self):
        return "My name is %s, nice to meet you!" % self.name

Then we must summon our Wizard!

summon = WordWizard()

Let's call on our wizard!

summon('apple')

What impudence! His response was I will change your words! For the better of course. See: ppl.

(NOTE)
You only need to do

def remove_vowels(self, word):
        return ''.join([letter for letter in word if letter.lower() not in 'aeiou'])

#3

Hahaha! This was amusing. Love a good wizard. But do you know why my code isn't passing, despite displaying correctly? I already passed this test, but I wanted to go back and try a different solution. Now it won't pass :frowning:


#4

I was about to put that in there that you didn't return. Beat me to it! lol


#5

I have problem also

def anti_vowel(text):
vowel = ["A","E","I","O","U","a","e","i","o","u"]
x = []
b = []
s = ""
for f in text:
x.append(f)
print x
for i in x:
print "text =" + i
for z in vowel:
print "vowel =" + z
if i == z:
n = "remove"
print n
x.remove(i)
print x
break
elif i != z:
n = "still"
print n
return s.join(x)
print s.join(x)

the result are like this

anti_vowel("Hey Look Words")

Hy Lk Words
anti_vowel("LookWords")
LkWords
anti_vowel("Words")
Wrds

I'm not sure why
Please help


#6

Hi everyone,

I am having an issue with mine and I can't seem to find the error. Thanks for taking a look.

vowels = ["A", "E", "I", "O", "U", "a", "e", "i", "o", "u"]

def anti_vowel(text):
output = ""
for char in range(len(text)):
consonant = True
for vowel in vowels:
if char == vowel:
consonant = False
if consonant == True:
output += text[char]
return output


#8

My code works:

def anti_vowel(text):
    
    for i in "aeiouAEIOU":
        text = text.replace(i,"")
    return text

#9

That's ingenious.

Good job!


#10

Would you mind explaining the "text.replace" line you have used there? have'nt quite wrapped my head around that well.


#11

def anti_vowel(text):
anti=""

Vowel =["A","E","I","O","U","a","e","i","o","u"]
for c in  text:
    if c not in Vowel:
        anti=anti+c

return anti

#12

Here's how i did it

def anti_vowel(text): #creating a function with an argument called 'text'.
    removal = "" #making an empty string to which we are gonna add onto later.
    vowels = ['a','e','i','o','u','A','E','I','O','U'] # list of the vowels.
    for i in text: #iterating through each letter in the 'text'.
        if i not in vowels: #says it in the code             
            removal = removal + i #adding the letter that wasn't in the 'vowel' list onto the new one we created earlier
    return removal #you know what this does.

print anti_vowel('Hey there! how you doing?')

With some help from @rubyblaster52470 code above.


#13

concise and effective, thank you for this solution.


#14

One day I want to be a Wizard like you zeziba! But today, I will have to settle for apprentice.

Thanks zeziba!


#15

My code

def anti_vowel(text):
    removtext = []
    for c in text:
        if c in "aeiouAEIOU":
            c=""
        else:
            removtext.append(c)
    return ''.join(removtext)

#17

have developed almost a similar code.

def anti_vowel(text):
text1=""
for x in text:
if x not in 'aeiouAEIOU':
text1+=x
return text1


#18

Here's my code. I'm suprised no one used the .lower() fuction besides me.

def anti_vowel(text):
    text1 = str(text)
    phrase = ""
    for char in text1:
        if char.lower() == "a" or char.lower() == "e" or char.lower() == "u" or char.lower() == "o" or char.lower() == "i":
            pass
        else:
            phrase +=char
    return phrase
print anti_vowel("Hey look Words!")

#19

Did you figure it out?

He's looping through the vowels, then replacing all vowels found in the variable 'TEXT' with empty strings ("") so it will output no vowels in 'TEXT' when printing in the console so Codecademy will take it as good and valid.

Great Job for jmacalua!


#20

For the appreciation of lists:

string = raw_input("Type something here: ")

vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]

def anti_vowel(text):
	textlist = []
	for i in text:
		textlist.append(i)
	for j in vowels:
		while j in textlist:
			textlist.remove(j)
	text = "".join(textlist)
	print text
	return text

anti_vowel(string)

I thought my code is quite good until I read this topic. :smiley:
At least it works.


#21

Clean, simple and effective. Nice work!