Hazwell
Hazwell

Reputation: 19

TypeError: 'float' object not callable in Python

I'm pretty new to coding so this may be a silly problem but when I try to run my programme I get the error mentioned in the title. The bit of code which seems to be the problem is this:

def branch(replicas):
    ER = d * 0.5 * w
    N0 = len(replicas)
    newReplicas = []   ##### Error on this line 

    for j in range( len(replicas) ):

        replica = replicas[j]

        r2 = 0

        for x in replica:

            r2 += x * x

            V = 0.5 * mass * w**2 * r2

            W = exp(-(V - ER) / rootT)

            mn = int(W + random.uniform(0,1))

            if mn >= 3:

                newReplicas.append( replica )

                newReplicas.append( replica )

                newReplicas.append( replica )

            elif mn == 2:    

                newReplicas.append( replica )

                newReplicas.append( replica )

            elif mn == 1:

                newReplicas.append( replica )

    replicas = newReplicas
    N1 = len(replicas)
    ER = ER + ((hbar/deltaT)(1-(N1/N0)))

Any help would be appreciated. Thanks in advance!

Upvotes: 1

Views: 255

Answers (1)

James Hurford
James Hurford

Reputation: 2058

I think your problem lies here

ER = ER + ((hbar/deltaT)(1-(N1/N0)))

I think what you're after is this

ER = ER + ((hbar/deltaT)*(1-(N1/N0)))

What Python thinks you want is to call a object of the value returned by evaluating

hbar/deltaT

So if

hbar = 2.0
deltaT = 1.0

then it thinks your trying to call the float object it creates, as in this case it would be a float object of the value 2.0, with the parameter of the result of evaluating

1-(N1/N0)

Since float objects are not callable, this doesn't work, and throws and exception.

Essentially you can fix this by putting the multiplication operator between

(hbar/deltaT)

and

(1-(N1/N0))

ending up with

((hbar/deltaT)*(1-(N1/N0)))

Which is what I think you're trying to do. Unless you didn't want to do multiplication

Upvotes: 1

Related Questions