Matthew Gregoire
Matthew Gregoire

Reputation: 65

TypeError: 'int' object is not callable for a recursive function

a = 3

def f(x):
    x = (x**3-4*x)/(3(x**2)-4)
    return x

while True:
    print(a)
    a = f(a)

I'm getting a type error here, and I'm not sure why. I'm trying to run this recursive function, is there any way to fix this?

Upvotes: 0

Views: 719

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 118001

You need a * operator after your parentheses. Multiplication is only implied in mathematical notation in this context, in Python it looks like you're trying to call a function.

3(x**2)

So it would be

3*(x**2)

For example

>>> 3(5*2)
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    3(5*2)
TypeError: 'int' object is not callable
>>> 3*(5*2)
30

Upvotes: 5

Related Questions