3

In python I'm trying to do the following to define a function:

count_letters(word) = count_vowels(word) + count_consonants(word)

But for some reason, it is wrong. I'm getting this error:

SyntaxError: can't assign to function call

How can I fix it?

Thank you

martineau
  • 119,623
  • 25
  • 170
  • 301
user1719345
  • 51
  • 1
  • 2
  • 5

6 Answers6

5

This is not how you declare a function in python. What you want to write is:

def count_letters(word):
    return count_vowels(word) + count_consonants(word)

That is if you already have a count_vowels and a count_consonants function.

Michael
  • 7,316
  • 1
  • 37
  • 63
Dean Elbaz
  • 2,310
  • 17
  • 17
4

The result of function call count_letters(word) is not assignable. That's as easy as that.

I don't believe it can work in python though, you should have an error like that:

SyntaxError: can't assign to function call
Antoine Pelisse
  • 12,871
  • 4
  • 34
  • 34
3

You need to replace it with a proper function definition:

def count_letters(word):
    return count_vowels(word) + count_consonants(word)

The syntax you're trying to use is not valid Python.

Chris Taylor
  • 46,912
  • 15
  • 110
  • 154
2

May be what you want to do is something like

def count_letters(word):
    return count_vowels(word) + count_consonants(word)
6502
  • 112,025
  • 15
  • 165
  • 265
1

If I gather correctly, you're trying to create a function. However, what you have right now is not valid syntax--to Python, it looks like you're trying to assign a value to a function call (count_letters(word)), which is not permissible in Python. count_letters = count_vowels(word) + count_consonants(word) would work, but is not what you want.

What you should do in order to declare the function is the following:

def count_letters(word):
    return count_vowels(word) + count_consonants(word)
jdotjdot
  • 16,134
  • 13
  • 66
  • 118
-2

having defined function: count_vowels(word) and count_consonants(word)

then you can do this: count_letters = count_vowels(word) +count_consonants(word)

hope it help! thanks