Anti_vowel


#1



I'm trying to figure out what I need to change about this code to get it to work. I've seen the various solutions others are using for this assignment, but I started with the if statement in it and want to know if there's something simple I'm missing that would get this to work.


keep receiving "Your function fails on anti_vowel("Hey look Words!"). It returns "" when it should return "Hy lk Wrds!"."


def anti_vowel(text):
    word = ""
    for i in text:
        if i == "a" or "A" or "e" or "E" or "i" or "i" or "o" or "O" or "u" or "U":
            continue
        else:
            word += i
    return word


#2

I fixed it by changing the code to
def anti_vowel(text):
word = ""
for i in text:
if i == "a" or i == "A" or i == "e" or i == "E" or i == "i" or i == "I" or i == "o" or i == "O" or i == "u" or i == "U":
continue
else:
word += i
return word

but I'm still curious why this is necessary


#3

Since the question asked to remove all the vowels from the text
and instead of writing

if i == "a" or i == "A" or i == "e" or i == "E" or i == "i" or i == "I" or i == "o" or i == "O" or i == "u" or i == "U":

you could simply use this

for i in text.lower():
    if i in ("aeiouAEIOU"):
        continue

#4

I did fix my code, but for the sake of playing with it I tried what you suggested,
I replaced:

for i in text:
        if i == "a" or i == "A" or i == "e" or i == "E" or i == "i" or i == "I" or i == "o" or i == "O" or i == "u" or i == "U":
            continue

with:

for i in text.lower:
    if i in ("aeiouAEIOU"):
        continue

and it threw the error "Oops, try again. Does your anti_vowel function take exactly one argument (a string)? Your code threw a "'builtin_function_or_method' object is not iterable" error."

This is what I have currently:

def anti_vowel(text):
    word = ""
    for i in text.lower:
        if i in ("aeiouAEIOU"):
            continue
        else:
            word += i
    return word

#5

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