关于python:防护计算程序的错误

Error for fencing calculation program

本问题已经有最佳答案,请猛点这里访问。

我的目标是在python中创建一个程序,允许用户输入每米围栏的成本,围场的长度和宽度,程序应该计算并打印周长,然后是报价。 我遇到了一些问题,遗憾的是我对Stack Overflow的研究没有成功。 我的代码如下(请记住我只是一个初学者)

1
2
3
4
5
6
7
8
9
10
11
12
    from turtle import*
print ("Welcome to the fencing quote calculator")
print ("In this program, you will be able to input the size of the padock as well as the cost of the fence per meter")
again =""
perMetre = input(str(("Please input the cost per metre in numbers without a dollar sign")
width = input("Please input the width of the paddock in metres")
length = input("Please input the length of the paddock in metres")

perimeter = (width+2)
print ("The perimeter of this paddock is",perimeter)
cost = int((perimeter)*(perMetre))
print("{:.2f}".format(cost))

错误是TypeError:无法将'int'对象转换为str隐式错误代码。
如果你能用非常简单的术语解释这一点我会非常感激。
谢谢 :)


请参阅以下替换代码中的注释。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from turtle import*
print ("Welcome to the fencing quote calculator")
print ("In this program, you will be able to input the size of the padock as well as the cost of the fence per meter")
again =""
perMetre = input(str(("Please input the cost per metre in numbers without a dollar sign")
width = input("Please input the width of the paddock in metres")
length = input("Please input the length of the paddock in metres")

# need to convert"numbers" currently input as strings to floating point numbers
perMetre = float(perMetre)
width = float(width)
length = float(length)

# also fix perimeter equation?
#perimeter = (width+2)
perimeter = (width + length) * 2.0
print ("The perimeter of this paddock is",perimeter)
cost = perimeter * perMetre
print("{:.2f}".format(cost))