Anti_vowel


#1

can i know why my code is not working with “e” :face_with_raised_eyebrow:

def anti_vowel(text):
    newstr = ""
    vowels = ('a', 'e', 'i', 'o', 'u')
    for x in text.lower():
        if x in vowels:
            newstr = text.replace(x, "")        
    return newstr
print(anti_vowel("Hey look Words!"))

Result: Hey lk Wrds!


#2

this code:

def anti_vowel(text):
    newstr = ""
    vowels = ('a', 'e', 'i', 'o', 'u')
    for x in text.lower():
        if x in vowels:
            newstr = text.replace(x, "")        
            print newstr
    return newstr
print(anti_vowel("that the thin host lust"))

perfectly demonstrates the problem why your code isn’t working


#3

Hai,
Sorry but I did not understand the difference between both the codes. :expressionless:


#4

In inserted a print statement + different string as argument at function which gives us output, perfectly demonstrating why your code is not working. Did you run the code and look at the output?

you replace from text, which contains the original string which isn’t modified. So newstr will only not contain the vowel which was removed last


#5

got it! Thanks for explaining in detail
thank you :slight_smile:


#6

I always dislike explaining this one, its tricky for some reason. You need to see that storing in a different variable will have unintended consequences, which is what i use the code for, where i put on purpose all the different vowels


#7

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