Anti_vowel - only returns '!'


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":
        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.


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


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