Antivowel


#1

Hi, I wanted to use the list to store all of the vowels in this exercise but now the code does not work. What have I missed?

def anti_vowel(text):
    vowel=['a','e','i','o','u','A','E','I','O','U']
    n=0
    s=''
    while n < len(text):
        if text[n] == vowel:
            n=n+1
        else:
            n=n+1
            s=s+text[n]
        return s

I'm getting: Your function fails on anti_vowel("Hey look Words!"). It returns "e" when it should return "Hy lk Wrds!".


#2

a function ends the moment a return keyword is reached, if a return keyword is reached in a loop, the loop breaks

place return outside the while loop


#3

def anti_vowel(text):
    vowel=['a','e','i','o','u','A','E','I','O','U']
    n=0
    s=''
    while n < len(text):
        if text[n] in vowel:
            n=n+1
        else:
            n=n+1
            s=s+text[n]
    return s

Still doesn't work.
This time:
Oops, try again. Your code looks a bit off--it threw a "string index out of range" error. Check the Hint if you need help!


#4

you should increase n after adding text[n] to s, otherwise you miss the first letter and the last letter gives an index error


#5

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