Anti-vowel


#1



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


Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "H" when it should return "Hy lk Wrds!".


Been stuck on this one for days. Any suggestions on which units I can go back and review to help me wrap my head around this? Guidance appreciated.


vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']

def anti_vowel(text):
    
    n = ''
    
    for letters in text:
        if letters not in vowels:
            n += letters
        result = n
        return result


#2

a function ends the moment a return keyword is reached

Even when the return keyword is reached in a loop, the function needs to end, so the loop will break

so, your loop breaks in its first iteration

place return outside the loop so your whole can run to reverse the string


#3

Strings are immutable on like lists so you cant add characters directly except via concatenation...Try using the .replace("a", "replacement here")...Or just go through the piece. It worked
def anti_vowel(text):
for v in text:
if v in "aeiouAEIOU":
text = text.replace(v,"")
print text
else:
text = text.replace(v,v)
print text
return text


#4

very true stetim94. return must be outside the loop


#5

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