8. anti_vowel


#1

Task:
Define a function called antivowel that takes one string, text, as input and returns the text with all of the vowels removed._

For example: antivowel("Hey You!") should return "Hy Y!"._

Don't count Y as a vowel.
Make sure to remove lowercase and uppercase vowels.

My code:

def anti_vowel(text):
    new_w = ""
    for letter in text:
        if letter == "a":
            retrun new_w = text - letter

print anti_vowel("abc")

Error!

    retrun new_w = text - letter
               ^
SyntaxError: invalid syntax

#2

Two errors, the first spelling of return, the second attempting to return a statement. return can only pass a value, not a statement.

Value can be interpreted as expression, which includes a function call, or a function itself.

Three errors, actually. There is not such thing as,

text - letter

as strings are concerned. There is no way to actually remove a letter from a string. We have to manipulate it and store it back in a variable (which can be the same one, this is reassignment--totally valid).


#3

Could You please tell me with what I should replace "vowel" in

    for letter in text:
        if letter != vowels:

Whole code:

vowels = ["a", "e", "i", "o", "u"]

def anti_vowel(text):
    new_w = ""
    for letter in text:
        if letter != vowels:
            new_w = new_w + letter
    return new_w

print(anti_vowel("abc"))

#4

vowels = ["a", "e", "i", "o", "u"]

def anti_vowel(text):
    new_w = ""
    index = 0
    for letter in text:
        if letter != vowels(index):
            index = index + 1
            new_w = new_w + letter
    return new_w

print(anti_vowel("abc"))

Are not working too.

Traceback (most recent call last):
  File "python", line 12, in <module>
  File "python", line 7, in anti_vowel
TypeError: 'list' object is not callable

#5

Any iterable will do,

for letter in text:
    if letter.lower() in 'aeiou':

#6

Thank You.

vowels = ["a", "e", "i", "o", "u"]

def anti_vowel(text):
new_w = ""
for letter in text:
if letter.lower() not in vowels:
new_w = new_w + letter
return new_w

print(anti_vowel("abc"))


#7

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