8. anti_vowal


#1

def anti_vowel(text):
    output=""
    for i in range(0,len(text)):
        if text[i] in "aeiouAEIOU" == False:
            output= output+text[i]
    return output

Why does the code only return "" no matter what i input?

Thanks


#2

First off you can say for i in text since you need to go through all of the letters anyway. Second, you need to change your text[i] (in both your if statement and your output =) to just i because i is returning each letter in text. Also, I believe the right syntax for an in statement doesn't require ==. Since we're basically saying if the next letter is a vowel we need to pass, otherwise, we need to add it to the output. I hope I explained it alright.

def anti_vowel(text):
    output = ""
    for i in text:
        if i in "aeiouAEIOU":
            pass
        else:
            output += i
    return output

#3

Thank you for you answer.

I just found out that the problem may occur because of "== False"

I changed the condition to "if text[i] not in "aeiouAEIOU":" then it went well.

I am curious why "== False" will cause problem tho


#4

I think it's because you would use for i in text or for i not in text since it's a for statement that doesn't take an operand like that.


#5

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