Anti_vowel : Please Help!


#1

def anti_vowel(text):
remove = ""
for index in range(len(text)):
if text[index] == 'A' or text[index] == 'a'
or text[index] == 'E' or text[index] == 'e'
or text[index] == 'I' or text[index] == 'i'
or text[index] == 'O' or text[index] == 'o'
or text[index] == 'U' or text[index] == 'u' :

        pass

    else :
        remove += index

return remove

I'm gettin error : File "python", line 4
if text[index] == 'A' or text[index] == 'a'
^
SyntaxError: invalid syntax

Where did I go wrong?


#2

My guess is the huge or condition you have going on needs to be all on the same line for the compiler to correctly process the condition.


#3

Bear in mind it would be easier to treat the string text as a string and not as a list of characters:

def anti_vowel(text):
    result = ""
    for index in text:
        if index == 'A' or index == 'a' or index == 'E' or index == 'e' or index == 'I' or index == 'i' or index == 'O' or index == 'o' or index == 'U' or index == 'u':
            #do nothing
            thing = 0
        else:
            result += I
    return result

#4

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