Anti-vowel


#1


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

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

However it produces "Hy" when run.


vowels = {
    'a': ['a','A'],
    'e': ['e','E'],
    'i': ['i','I'],
    'o': ['o','O'],
    'u': ['u','U']        
    }

def anti_vowel(text):
    new_string = ('')
    for c in text:
        if c in vowels:
            new_string = text.replace(c,'')
    return new_string

print(anti_vowel('Hey'))


#2

This doesn't change the value of text. In the loop you make new_string the same as text with one vowel removed. The next time the loop runs the old vowel will be there again and the next one will be removed.

Also I don't think a dictionary is the right thing to use here. You only go through the keys, that means capital vowels won't be deleted.


#3

def anti_vowel(text):
    vowels = ('aeiouAEIOU')
    for c in text:
        if c in vowels:
            text = text.replace(c,'')
    return text

Lesson cleared. Thanks.


#4

No problem.

You should also be careful with looping through the text variable while changing it, although that shouldn't be a problem in this case.


#5

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