Anti_vowel


#1



Hey guys! Here is my code, is there any problem with this ? I dont understand what wrong with the else statement.Did i put it in wrong place?


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


When I delete the else statement then the result is:
Your function fails on anti_vowel("Hey look Words!"). It returns "Hey lk Wrds!" when it should return "Hy lk Wrds!".


Somebody help me please!!


Replace this line with your code.


#2

That link does not provide a link to your code but instead to ours. So you still need to post your code the link just provides a reference to the exercise you are on.


#3

def anti_vowel(text):
new_text = ""
for i in text:
if i in "aeiouAEIOU":
new_text = text.replace(i,"")
return new_text
else:
return text
Okay!! I posted my code!


#4

In the line "new_text = text.replace(i, "")" you just need text instead of new_text. Hope this helped :slight_smile:


#5

Perhaps you could make a new list at the top before your defined function like...

vowels = ["A", "a", "E", "e", etc...]

Then try checking to see " IF i IN vowels" then return 'new_text = new_text + ""'.
That would just replace the vowel with nothing.
Then you could do an "else" after the "if" that would just add the character (your variable "i") in (since the rest aren't vowels).

It's pretty much the same idea as yours, but just puts that "aeiouAEIOU" into a list on top.


#6

Thank you! I fixed it.


#7

this is also works:

def anti_vowel(text):
empty_text = ""

for n in text:
    if n == "a" or n== "e" or n == "i" or n== "o" or n =="u":
        pass
    elif n == "A" or n== "E" or n == "I" or n== "O" or n =="U":
        pass
    else:
        empty_text += n
return empty_text

print anti_vowel("Hey You!")


#8

Hi, here is my version:

def anti_vowel(text):
    vowels="aeiou"
    unvoweled=""
    for t in text:
        assist_counter=0
        for v in vowels:
            if v==t.lower():
                assist_counter=1
                break
        if assist_counter!=1:
            unvoweled+=t
    return unvoweled
    
print anti_vowel("It's a test of anti-voweling!")

#9

Hi, I'm using this code on my program. it's almost similar like @roaster97 did. But I do the reverse

def anti_vowel(text):
new_text="";

for n in text:
    if n not in "aeiouAEIOU":
        new_text += n;
return new_text;

print anti_vowel("Hello world");

it worked on mine


#10

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