8. anti_vowel. Syntax error: "Can't assign to function call." Help


#1

Here’s my code:

I don’t understand the error?

def anti_vowel(text):
  vowels = "a", "e", "i", "o", 'u'
  for w in text:
    if i in vowels == w in text:
      text() -= vowels(i)
    return text

print anti_vowel("Hey you!")

#2

here:

text() -= vowels(i)

text() is a function call, not sure why you made a function call. Its what the error refers to, but i easily see more mistakes


#3

I tried “text(i) -= vowels(i)” It may be my understanding of function calls that’s messing me up. I see this code as taking the “i” in text and subtracting it by the “i” in vowels


#4

anti_vowel is a function:

def anti_vowel(text):

the def keyword indicates the definition of a function, then anti_vowel is the name of the function, then between the parentheses you define the parameter(s) then you call the function here:

print anti_vowel("Hey you!")

but text is a string. So doing:

text()

will attempt to call a string, but strings are not callable. Functions are, strings are not

here:

vowels = "a", "e", "i", "o", 'u'

this should be a list, how do we make a list? Feel free to check earlier lessons or documentation if need a syntax refresher.

could you explain me how this comparison:

if i in vowels == w in text:

is suppose to work?


#5

I thought that it would take the i in vowels, the (a, e, i, o, u), and the w in text (“H” “e” “y” “y” “o” “u” “!”) and subtract any that would be equal in I.D. Which I believed to be the vowels


#6

Sorry if I’m saying anything wrong here, but I’m truly trying my hardest.


#7

no, the in keyword check if something is present within a string or list, for example:

print "a" in "abc"

will print True. So we can use this, we can check if w is in vowels.


#8

So it checks if something is present. So I can use that to check it but I still don’t understand where to go from here.


#9

first you need to fix vowels variable, you need to make it a list.

we could construct a new string when w is not in vowels, just like with reverse a few exercises back


#10

This is my new code. Still won’t work?

def anti_vowel(text):
  vowels = ["a", "e", "i", "o", 'u']
  anti_v = ""
  for i in text:
    if i not in vowels:
      anti_v += i
  return anti_v
    

print anti_vowel("Hey you!")

#11

what about uppercase vowels? A, E, I and so on?


#12

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