Problem with anti_vowel


#1

def anti_vowel(text):
d = []
trash = []
for x in text:
if (x == "A" and x == "a"):
return trash.append(x)
elif (x == "E" and x == "e"):
return trash.append(x)
elif (x== "I" and x == "i"):
return trash.append(x)
elif (x == "O" and x == "o"):
return trash.append(x)
elif (x == "u" and x == "u"):
return trash.append(x)
else:
d.append(x)
return "".join(d)

I don't understand why my code isn't working, if you could please enlighten me?
Thank you in advance


Anti_vowel
#2

Hi @netpro56931,

Your process for checking whether x does not refer to a vowel is overly complex and has some errors in it. Whenever x does refer to a vowel, you do not need to do anything with it. Therefore, you do not need this trash object ...

trash = []

Also discard all occurrence of this ...

return trash.append(x)

It is when x does not refer to a vowel that you need to take action.

To test whether x does not refer to a vowel, simply do this ...

if x.lower() not in "aeiou":

That is the condition under which you need to do this, so that x is included in the result ...

d.append(x)

The only return statement that you need is this one, which makes the result available when it is complete ...

return "".join(d)

#3

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