Why is this not working?

def anti_vowel(text):
    vowel='a' or 'e' or 'i' or 'o' or 'u'or 'A' or 'E' or 'I' or 'O' or 'U'
    for i in text:
    while x != l: 
        if word[x]==vowel:
    print ''.join(word)


Compare your code to this...

def anti_vowel(text):
    vowels = 'aeiou'
    new_text = ''
    for i in text:
        if i.lower() not in vowels:
            new_text += i
    print new_text
    return new_text

Your vowel variable violates the rules of python in many ways. or is to be used in a conditional, not a variable. You filled out a variable like it is a list. Your word list is not needed, as a for loop can just run through a string without it being split so much. Your while loop is unnecessary, and does nothing useful, for this program. Try comparing it to the code I provided, and see how it works. If you need clarification, ask.


def anti_vowel(text):
i = 0
text2 = [ ]
length = len(text) - 1
while i <= length:
print text[i]
if text[i].lower() != 'a' and text[i].lower() != 'e' and text[i].lower() != 'i' and text[i].lower() != 'o' and text[i].lower() != 'u':
i = i + 1

str1 = ''.join(text2)
print str1
return str1

anti_vowel('Hey You!')


ok thanks for the help!


This works! My code was incorrect. Thanks!


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