Anti_vowel


#1


https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#

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'
    word=[]
    for i in text:
        word.append(i)
    
    l=len(word)
    x=0
    while x != l: 
        if word[x]==vowel:
            word.remove(x)
        x=x+1
    print ''.join(word)
anti_vowel("Hey")


#2

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.


#3

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':
text2.append(text[i])
i = i + 1

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

anti_vowel('Hey You!')


#4

ok thanks for the help!


#5

This works! My code was incorrect. Thanks!


#6

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