Anti_vowel - only returns '!'


#1

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


I thought my code would skip any vowels, and concatenate any non vowel characters to the new_string. However, only the '!' is concatenated.

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

def anti_vowel(text):
    new_string = ""
    for c in text:
        if c in "aeiouAEIOU":
            continue
    else:
        new_string = new_string + c
    return new_string

Can anyone please advise me If my strategy is poor, or have I made an error with the code?

This is my first forum post so apologies if it isn't a good one.


#2

the else is outside the for loop, so once the loop condition becomes false, else will add the last letter to new_string, you want to add c to new string every time if is false


#3

Perfect, I indented the else to get it within the loop and now it works, Thank you.


#4