1

我试图四处寻找答案,但是这里的问题似乎很高级(我是 Python 新手),或者是因为重新定义了我在脚本中无法捕捉到的含义。这是代码-

a = float(input("Enter the length(in inches)"))
b = float(input("Enter the width(in inches)"))
print ()
print ("The area of your shape is: "(a*b))

我收到错误TypeError: 'str' object is not callable

这是一个简单的脚本,我知道,但它正在进行中。

4

2 回答 2

11

假设您使用的是 Python 3,

print ("The area of your shape is: ", (a*b))
#                                   ^

你忘了一个逗号。

于 2012-08-28T13:40:17.850 回答
1

您可以使用以下方式打印值:

print ("The area of your shape is: ", (a*b))

或与

print ("The area of your shape is: {}".format(a*b))
于 2012-08-28T13:41:51.333 回答