Anti Vowel and the mysterious Extra Letters


#1

new_lst = [ ]

def anti_vowel(text):

for i in text:
    if i == "a"or i == "A":
        continue 
    elif i == "e"or i == "E":
        continue 
    elif i == "i"or i == "I":
        continue    
    elif i == "o"or i == "O":
        continue 
    elif i == "u"or i == "U":
        continue 
    else:
        new_lst.append(i)
return "".join(new_lst)

Okay so this is my code (it's not the most efficient but it's mine) it seems to work but why does it return bcd infront of the string?

I can only assume it was abcd before, but why is it there?

ERROR -Your function fails on anti_vowel("Hey look Words!"). It returns "bcdHy lk Wrds!" when it should return "Hy lk Wrds!"

Thanks in advance :smile:


#2

I had to change a couple of things to make your code work.. (not sure what the issue was with adding the bcd, but its fixed).

I moved new_lst variable inside the function (otherwise it doesnt read it)
I changed new_lst from == [] to '' (made it a string not a list)
Then at the bottom I made new_lst = new_lst + i (add the new letter to new_lst) as append is used for lists not strings.
Hope this helps :smiley:

def anti_vowel(text):
new_lst = ''
for i in text:
if i == "a"or i == "A":
continue
elif i == "e"or i == "E":
continue
elif i == "i"or i == "I":
continue
elif i == "o"or i == "O":
continue
elif i == "u"or i == "U":
continue
else:
new_lst= new_lst +(i)
return "".join(new_lst)