我正面临一个 TypeError: 'float' object is not callable

时间:2021-04-17 13:25:43

标签: python

def area_triangle(): # Function for area of triangle by herons formula
    a = float(input("Enter length of first side:"))
    b = float(input("Enter length of second side:"))
    c = float(input("Enter length of third side:"))
    s = (a + b + c)/2
    triangle = s*(s-a)(s-b)(s-c)**0.5
    print("Area of triangle =",triangle)

这是我遇到错误的代码块

3 个答案:

答案 0 :(得分:0)

triangle = s*(s-a)(s-b)(s-c)**0.5

在 Python 中不正确,乘法不会以这种方式进行。

triangle = s*(s-a)*(s-b)*(s-c)**0.5

答案 1 :(得分:0)

您的问题与第 6 行有关。 你有int (*ptr)[4] = arr;

应该是triangle = s*(s-a)(s-b)(s-c)**0.5

您忘记将 triangle = s * ( s - a ) * ( s - b ) * ( s - c) ** 0.5( s - a )( s - b ) 相互叠加

如果没有 ( s - c ),您将其作为 * 之类的函数调用,该函数将被解释为具有 (1)(2)(3) 值的调用函数 (1)(2),并调用函数 ( 1) 值为 3

2

答案 2 :(得分:-1)

只需将 * 放在三角形公式中的括号之间