Song
Song

Reputation: 328

Findind a triangle's area results in a error:'float' object is not callable

I am creating a test program to find the area of a 3d triangle like this one: this one I am having a problem with the last line which I expect to be perfect but reaulted in a type Error.

I lastly found out that I only set 1 argument, and it takes 2. I don't know how to use google because this is a specific problem. The main function is this:

def triangle3d(width, height):
    triangle2d = width*height/2
    length = math.cos(random.randint(3, 5))
    triangle3d = triangle2d*length
    assert (width*height*length)/2 == triangle3d;
    return triangle3d(triangle3d, triangle3d-2)
print(triangle3d(2, 4))

I expected it to just print out one number, but it resulted in a error message:

Traceback (most recent call last):
  File "C:/Users/Public/test.py", line 11, in <module>
    print(triangle3d(2, 4))
  File "C:/Users/Public/test.py", line 9, in triangle3d
    return triangle3d(triangle3d, triangle3d-2)
TypeError: 'float' object is not callable

Thanks!

Upvotes: 0

Views: 104

Answers (1)

hiro protagonist
hiro protagonist

Reputation: 46891

in your function you assign

triangle3d = triangle2d*length

only to try to call it later on (this is where the error is raised)

return triangle3d(triangle3d, triangle3d-2)

but if you just rename the local variable you will run into a RecrusionError...

your length can be negative. is that what you expect?

Upvotes: 2

Related Questions