当我运行脚本时,我得到一个TypeError
。
这是我所有的代码:
lawnCost = ("£15.50")
lengthLawn = float(input("Lengh of lawn: "))
widthLawn = float(input("Width of lawn: "))
totalArea = (lengthLawn) * (widthLawn)
print (("The total area of the lawn is ")+str(totalArea)+str("m²"))
totalCost = (totalArea) * float(15.50)
print ("The cost of lawn per m² is £15.50")
print ("The total cost for the lawn is ")+str(totalCost)
这是我得到的错误:
^{pr2}$如果有人能帮我指出正确的方向那就太好了,谢谢。在
如果有帮助的话,我可以在Windows7x64上运行Python3.3。在
在最后一行,
str(totalCost)
必须在print
的圆括号内:这是因为在python3.x中,}。因此,您的代码实际上是在尝试这样做:
^{pr2}$print
返回{另外,如果需要,下面是脚本的一个版本,它更干净、更高效:
基本上,我做了三件事:
删除了不必要的括号和
print
后的多余空格。删除了对
str
和float
的不必要调用。合并使用^{} 。
相关问题 更多 >
编程相关推荐