8/15: Anti_vowel - works in terminal but not codecademy


#1

Hi all,

I need some help. My code worked in my terminal but when i tried to run it on codecademy, it just won't work...Can someone help me understand why this is the case? I have had a few of these and it's making me really frustrated...

a = list()
def anti_vowel(text):
index=0
for letter in text:
if text[index] in "aeiouAEIOU":
index=index+1
continue
else:
a.append(text[index])
index = index + 1
print ''.join(a)


#2

Hi, I'll try to help:

First the "a = list()" should be defined inside of the function, but when i did that for some reason the output string was always adding "bcd" in front of the string without the vowels, which made me think that the error was due to the "a = list()", don't know the exact reason.

So i tried to replace the "a = list()" with "word = []" and the problem disappeared. And the code is like this:


Help with anti_vowel code
#3

Here is what I did, I felt this was simplistic

def anti_vowel(text):
    for char in "AEIOUaeiou":
        text = text.replace(char, '')
    return text

#4

@slobodank you can create a list either by doing

my_list1= list()
#or
my_list2 = []

#both work fine and you can perform list operations on them

#5


#6

thanks for the code...it's legit code :grin:


#7

def anti_vowel(text):
want = []
dwant = []
for i in range(len(text)):
if text[i] == "a" or text[i]== "e" or text[i]== "i" or text[i]== "o" or text[i]== "u" or text[i] == "A" or text[i]== "E" or text[i]== "I" or text[i]== "O" or text[i]== "U":
dwant.append(text[i])
else:
want.append(text[i])
print "".join(want)

I have the same problem with getting it correct on the terminal but receiving an error message from codeacademy! Help!?