Anti_Vowel issues


#1



Hello I'm having issues with this problem:

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#


I'm getting this error when I run my program:

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


If I am reading through my code correctly, it should move through "original" and if my index, "i", is a vowel is should replace it with nothing, thereby removing it.

My code seems to skip the first "e" when the phrase "Hey Look Words!" is used. When I use my code with other words or phrases it doesn't do this. For example if I just put in "eee" it correctly returns nothing, but if I put in "eEe" it will return E, conversely if I input "EeE" the code returns e.

Why is my code doing this? (code is below)


def anti_vowel(original):
    for i in original:
        if i in "aeiouAEIOU":
            new=original.replace(i, "")
    return new


#2

original is the original text, if you replace all occurrences of one character, you'll get a new string with that character having been replaced, with all others being the same.


#3

Okay I think I understand you, my variable "new" gets overwritten each time the loop executes and so after one of the variables have been removed the whole original string gets written in again. So, after I've removed "e" for example and it moves to "i" it will put the "e" back in when it re-writes new.

I've re-written my code to add to the variable new if the letter isn't a vowel, rather than to remove letter if it is and it worked.

Thanks for your help.


#4

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