Anti vowel . what is wrong with my code?


Define a function called anti_vowel that takes one string, text, as input and returns the text with all of the vowels removed.

For example: anti_vowel("Hey You!") should return "Hy Y!".

Don't count Y as a vowel.
Make sure to remove lowercase and uppercase vowels.

my code

def anti_vowel( text ):
for i in text :
if i =="a" or i=="e" or i=="i" or i=="o" or i=="u" or i =="A" or i=="E" or i=="I" or i=="O" or i=="U":
text = text.replace(i,"")
return text
print text

my code only works on first word


We cannot see this variable in global scope.

This method does not need to be in a conditional. For practice, try doing this exercise without using a built-in.

for i in 'aeiouAEIOU':
    text = text.replace(i)
return text


didnt understand what you said.
can you explain it better thanks


To repeat, for practice try doing this exercise without using .replace(). Keep the above example for future reference. If you cannot fix your own code, then it means you do not fully understand what should be happening.

We learn more by doing things from scratch, and getting a feel for how to write an algorithm.


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