Python:TypeError:“int”对象不可调用。很可能是个简单的解决办法。我似乎不知道怎么修理我

2024-10-02 02:28:09 发布

您现在位置:Python中文网/ 问答频道 /正文

这是代码的a部分。

import math

length_centre=eval(input("Enter length from centre to corner of pentagon: "))
side_length= 2*length_centre*(math.sin(math.pi/5))
print(side_length)

areaP =(5((side_length)**2))/(4*((math.tan)((math.pi)/5)))
print(areaP)

代码错误:

面积=(5((4)**2))/(4*((数学。棕褐色)((数学.pi)/5) )) TypeError:“int”对象不可调用


Tags: to代码fromimportinputevalpi数学
1条回答
网友
1楼 · 发布于 2024-10-02 02:28:09

编程语言不像书面数学那样有隐式乘法,因此5((side_length)**2)是不合法的,它试图将5作为带有参数side_length ** 2的函数调用。我猜你想要5 * side_length**2(除去一些不需要的无关paren,因为求幂比其他数学运算绑定得更紧密)。在

清理干净,你会有:

import math

# Use float to get the specific type you want, rather than executing whatever
# code the user types. If this is Py2, change input to raw_input too,
# because Py2's input is equivalent to wrapping raw_input in eval already
length_centre=float(input("Enter length from centre to corner of pentagon: "))

# Strip a whole bunch of unnecessary parens
side_length = 2 * length_centre * math.sin(math.pi / 5)
print(side_length)


# Strip a whole bunch of unnecessary parens (left in some technically unnecessary parens
# because they group the complex operands for the division visually)
areaP = (5 * side_length**2) / (4 * math.tan(math.pi / 5))
print(areaP)

相关问题 更多 >

    热门问题