8. anti_vowel


#1



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


def anti_vowel(text):
vowels='a,e,i,o,A,E,I,O,U'
text=raw_input("Type ur text here: ")
if "text contains vowels.":
del(vowels)
return text
else:
return text

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


Replace this line with your code.


#3

Hey @webpro43670 ! The quotation marks around your if statement is probably tripping your code up as you don't need them. Having them makes the words a string, float, integer, etc. Remove them and try again. Or try this code:

def anti_vowel(text):
    word = ''
    for letter in text:
        if not (letter in 'aeiouAEIOU'):
            word += letter
    return word

Hope that help! :slight_smile:


#4

thanks man, that really did it.


#5

@chipjumper36731, I really like your solution! It is succinct and has only one loop.

Here is what I came up with, using a nested for loop:

def anti_vowel(text):
    vowels = "aeiouAEIOU"
    for i in text:
        for j in vowels:
            if i == j:
                text = text.replace(i, "")
    return text

#6

@webpro43670 Glad I could help! :upside_down: and for the record, I'm a woman :joy:


#7

@wowpalvabbit Thanks for the compliment! And your nested for loop is really clever, I like the way you designed it, and it may come in handy during the censor exercise, as they want you to do a similar thing :slight_smile:


#8

sorry, my bad...didn't know.


#9

You're fine! Nothing wrong with that. Glad to help!:slight_smile:


#10

I'm using something similar but w/ a lower() to convert the string to lowercase. However this is not working...

word = raw_input("Type a word: ")
lowerC = word.lower()
def anti_vowel(text):
    vowel = "aeiou"
    for i in vowel:
        text = lowerC.replace(i,"")
    return text

print anti_vowel(text)

#11

text is a variable, it is not defined


#12

But after that fix replace() still not working... Thanks though!

[quote="datapro19957, post:10, topic:48624"]
word = raw_input("Type a word: ")
lowerC = word.lower()
def anti_vowel(text):
vowel = "aeiou"
for i in vowel:
text = lowerC.replace(i,"")
return text

print anti_vowel(text)
[/qu


#13

cant seem to find wats wrong with it but why dont u try the code as stated above by chipjumper36731


#15

def anti_vowel(text):
vowel = raw_input("Type a word: ")
for i in text:
lists = 'aeiouAEIOU'
if i not in lists:
vowel += i
return vowel


#16

What is wrong in this?

vowel = ['a','e','i','o','u','A','E','I','O','U']
string = raw_input("Input text: ")
def anti_vowel(string):
new = ""
for i in range(len(string)):
for j in range(len(vowel)):
if string[i] != vowel[j]:
new += string[i]
break
return new


#17

You are using string[i] to refer to a character within a string.


#18

could you please correct my code
??


#19

@datapro19957 your problem is that you turn the string into lowercase outside the actual function. Since it is not part of the function, Python is probably not running the command making the text not lowercase. Try putting the second line of code inside the anti_vowel function. If it still doesn't work then let me know.

Good luck! :slight_smile:

-- @chipjumper36731


#20

def anti_vowel(text):
....count = len(text)
....x = 0
....ret = ''
....while x < count:
........if not (text[x] == "e" or text[x] == "o" or text[x] == "a" or text[x] == "i" or text[x] == "u" or text[x] == "A" or text[x] == "E" or text[x] == "I" or text[x] == "O" or text[x] == "U"):
............print text[x]
............ret += text[x]
........x += 1
....return ret


#21

Hi! Can you help me with figuring out why isn't my code working? As for me, it should be doing the same thing you wrote down. Yet, it returns 'none'. Thank you in advance!

def anti_vowel(text):
vowellist = 'euioaEUIOA'
new = ''
for letter in text:
if letter in vowellist == False:
new += letter
return(new)


#22

You have to add a pair of parentheses to the condition of the if and now, with proper indentations, your code should work:

def anti_vowel(text):
  vowellist = 'euioaEUIOA'
  new = ''
  for letter in text:
    if (letter in vowellist) == False:
      new += letter
  return(new)

For anyone interested in more Pythonic solutions here is mine, more compact, solution using filter function:

def anti_vowel(text):
    return filter(lambda c: c.lower() not in ['a','e','i','o','u'], text)