8. anti_vowel



My code returns "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 am not entirely sure what I am doing wrong, and though my code may not be the most elegant solution, I think that it should work.

def anti_vowel(text):
    new_text = []
    pointless_variable = 17
    for char in text:
        if(char == 'A' or char == 'E' or char == 'I' or char == 'O' or char == 'U'):
            if(char == 'a' or char == 'e' or char == 'i' or char == 'o' or char == 'u'):
                pointless_variable = 17
                #As the name implies, the above variable is pointless. It was solely derived in order to give my two "if" checking statements something to do, and go to the next iteration in my for loop.
    return ''.join(new_text)


You are overthinking this. Try following this template:

        if INDIVDUAL_ITEM in "aeiouAEIOU":
    return PARAMETER

Make sure not to just follow the template and move on. I want to make sure that you understand how and why this works. If you have any questions, just ask.


Isn't my code exactly that template, but elongated?


Only difference is I append to a new list, and thus don't have to replace with nothing.


The one other difference I see is that you convert Parameter into a string, and instead of my two if statements with lots of or operators, you use an in keyword. But besides that, I think my code is basically the same idea, with an extra list. Is there some bit of logic I'm missing?


I understand why you code works, and could use it to solve the problem. However, I am also curious as to why my code doesn't work.



if(char == 'A' or char == 'E' or char == 'I' or char == 'O' or char == 'U'):
    if(char == 'a' or char == 'e' or char == 'i' or char == 'o' or char == 'u'):
        pointless_variable = 17

The code will only run through your second if statement if the char is a capital vowel. This means that your code eliminates vowels… so long as they’re capital letters.


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