我有一个错误:无法将序列乘以'float'类型的非整数

时间:2019-10-22 00:13:08

标签: python python-3.x

我正在尝试编译我的代码,但我不断收到错误:无法将序列乘以'float'类型的非整数。我不知道如何解决。

我尝试更改变量和代码等。在第11行出现错误,我正在使用codekulptor在线编译器。

a = float(input("Enter side A: "))

b = float(input("Enter side B: "))

c = float(input("Enter side C: "))

d = float(input("Enter side D: "))

e = float(input("Enter side E: "))

rect = (str(a*b))

sqaureleftside = (a - c)

sqaurerightside = (str(sqaureleftside - 0))

sqaure = (sqaureleftside ** 2)

trianglelegs = (str(e *sqaurerightside))

triangle = (str(trianglelegs/ 0.5))

totalarea = (rect + square + triangle)

print("Room Area: " + totalarea)

我们的形状异常,必须找到该区域。输入时,请输入:

Enter side A: 11

Enter side B: 2

Enter side C: 4

Enter side D: 7

Enter side E: 1

Answer:

Room Area: 53.5

1 个答案:

答案 0 :(得分:2)

您不必要地将计算转换为字符串。这是清理后的版本:

a = float(input("Enter side A: "))

b = float(input("Enter side B: "))

c = float(input("Enter side C: "))

d = float(input("Enter side D: "))

e = float(input("Enter side E: "))

rect = a * b

sqaureleftside = a - c

sqaurerightside = sqaureleftside - 0

square = sqaureleftside ** 2

trianglelegs = e * sqaurerightside

triangle = trianglelegs / 0.5

totalarea = rect + square + triangle

print("Room Area: " + str(totalarea))