Anti vowel


#1

def anti_vowel(text):
    text=str(text)
    y=len(text)
    vowels = "aeiou"
    p=0
    while (p <= y-1):
        for i in vowels :
            if i== text[p]:
                newstr = text.replace(text[p], "")
        for i in vowels.upper():
            if i== text[p]:
                newstr = text.replace(text[p], "")
        p += 1
    return newstr

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

can any one help me how to fix the error.


Anti_vowel
#2

the replace you use won't persist. Look at this code:

def anti_vowel(text):
    text=str(text)
    y=len(text)
    vowels = "aeiou"
    p=0
    while (p <= y-1):
        for i in vowels :
            if i== text[p]:
                newstr = text.replace(text[p], "")
                print newstr
        for i in vowels.upper():
            if i== text[p]:
                newstr = text.replace(text[p], "")
        p += 1
    return newstr
print anti_vowel("a bet which won't turn")

it is your code with a additional print statement and a function call.

As you can see, newstr is just a variable inside the loop. it resets every time, hopes this helps you. If more help is required let me know


#3

def anti_vowel(text):
text=str(text)
y=len(text)
vowels = "AEIOUaeiou"
p=0
while (p <= y-1):
for k in vowels :
if k== text[p]:
newstr = text.replace(text[p], "")
text=newstr
x=len(text)
else :
x=len(text)
y=x
p += 1
return text

Made the necessary changes. Thanks stetim94 you gave a valuable insight.