Stuck in 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 look Words!" when it should return "Hy lk Wrds!".


I would expect it to work, I can't find out what's the mistake. Could you guys please help me out?
Thanks in advance!


def anti_vowel(text):
    vowels = "aeiouAEIOU"
    res = ""
    for t in text:
        for v in vowels:
            if t == v:
                res = res+""
                break
            else:
                res = res+t
                break
    return res


#2

The logic would seem sound, but...

When t does not equal the current vowel, v, your else branch is affixing the letter to the result string without completing the vowel loop.

We may forego that inner loop and use an if statement with not in vowels...

if t not in vowels:
    res += t

#3

Wow! Didn't think of that, thanks a lot for the suggestion, now it works fine!

By the way, it's very nice how a number appears instead of my user name when you quote me :stuck_out_tongue:
I hope a moderator sees it and fixes it in the forum.

Thanks again!


#4

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