Practice Makes Perfect, anti_vowel


#1

def anti_vowel(text):
lists = []
vo = 'aeiouAEIOU'
for i in text:
if i != 'a' and i != 'A' and i != 'e' and i != 'E' and i != 'i' and i != 'I' and i != 'o' and i != 'O' and i != 'u' and i != 'U':
lists.append[i]
print lists
for letter in lists:
print ''.join(letter)
print anti_vowel('Hey You!')

i don't know what's wrong with my code, plz help..
Thank you!


#2

Find out what way it misbehaves and make sure you can reproduce it.

Ask yourself why it wouldn't behave as it does if it was doing as you wanted.

Confirm whether it's doing that or not.

Reconsider that part of the code.


#3

Hi everyone,

here is my trial:

def anti_vowel(text):
    text = list(text)
    for m in text:
        if m =="a"or m=="e"or m =="i" or m == "o" or m=="u":
            text.remove(m)         
    return "".join(text)
text = "Hey look Words!"
print anti_vowel(text)

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

Can anyone see what did I miss in the code?
Many thanks


#4

Can anyone help please?
the code works very well for other sentences like the one below but does not work with the "Hey look Words!" specially, it does not remove the last "o". Please help.

def anti_vowel(text):
    text = list(text)
    for m in text:
        if m =="a"or m=="e"or m =="i" or m == "o" or m=="u" or m=="A" or m=="E" or m=="I" or m == "O" or m=="U":
            text.remove(m)         
    return ''.join(text)
text = "what is wrong with you"
print anti_vowel(text)

#5

I have been looking at your code but I could not figure out why it is not working. :sweat:


#6

I have tried this sentence:

print anti_vowel("Hey look Words! ok me")

the output is:

Hy lk Wrds! ok m

and this:

print anti_vowel("Hey look Words! ok I am not sure but why it is not working")

Hy lk Wrds! k  m nt sr bt why t s nt workng
None

Then I changed the code a bit to this:

def anti_vowel(text):
    text = list(text)
    for c in text:
        if c in "aeiouAEIOU":
            text.remove(c)         
    return "".join(text)
print anti_vowel("Hey look Words!")

and the output is:

Hy lk Words!
None

This is driving me crazy :tired_face:


#7

Try making a list of vowels such as: vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]
And go from there. :wink:


#8

Thank you turtwigpo,
it still throws the same output:

def anti_vowel(text):
    text = list(text)
    vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]
    for c in text:
        if c in vowels:
            text.remove(c)         
    return "".join(text)
print anti_vowel("Hey look Words!")

Hy lk Words!
None

#9

Here is a snippet of code:

def anti_vowel(text):
    vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]
    anti = []
    for i in text:
        if i in vowels:
            pass

Hint: there is a else statement after this with a

anti.append(i)

And a

return

Try to go from there :relieved:


#10

Hi,
Please could anyone help me with my code
def anti_vowel(text):
text = ""
voewls = ["A", "E", "I", "O", "U", "a", "e", "i", "o", "u"]
for i in text:
if i not in voewls:
text += i
return text

print anti_vowel("Hey look Words!")


#11

Look at my examples up above your post :smile:


#12

Thank you so much turtwigpo, the code is now working but I am still wondering what was wrong in my previous code?

def anti_vowel(text):
    vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]
    anti = []
    for i in text:
        if i in vowels:
            pass
        else:
            anti.append(i)
    return "".join(anti)
print anti_vowel("Hey look Words!")

#13

You needed to use a list, that and there were a few other small errors you had to fix.
Sorry about my bad response: I'm kinda new to this "helping people stuff" :smiley:


#14

Thank you for your reply. It is ok no worries. Can you please show me these errors?


#15

Here is your old code:

def anti_vowel(text):
    text = list(text)
    for m in text:
        if m =="a"or m=="e"or m =="i" or m == "o" or m=="u":
            text.remove(m)         
    return "".join(text)
text = "Hey look Words!"
print anti_vowel(text)

Here is your new code:

def anti_vowel(text):
    vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]
    anti = []
    for i in text:
        if i in vowels:
            pass
        else:
            anti.append(i)
    return "".join(anti)
print anti_vowel("Hey look Words!")

#16

First of all you needed to make 2 lists, vowels, then anti. Then you looped through text, and if if i was a vowel, you would put it in your list anti, then print that. The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute. You had some parts of your code correct, such as your return statement, but you needed an if/else statement and a list pretty much. If you are satisfied with this, please mark this as a solution. :grin:


#17

Hi turtwigpo
sorry
how can I mark it as a solution? I have been looking for this icon but I cannot find it :grimacing:.
many thanks


#18

Never mind. U didn't create the topic. But thanks anyway. :grin:


#19

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