【发布时间】:2018-03-31 09:02:35
【问题描述】:
我写了一个计算三角形面积的代码
a = float(input("Enter the first side of triangle: \n"))
b = float(input("Enter the second side of triangle: \n"))
c = float(input("Enter the thrid side of triangle: \n"))
s = (a+b+c) / 2
area = (s*(s-a) * (s-b) * (s-c)) ** 0.5
print("The area of triangle is %0.3f" %area)
我使用的输入值是:25、4556、5544
我收到的错误是:
print("The area of triangle is %0.3f" %area)
TypeError: can't convert complex to float
有人可以帮我解决这个问题吗?当我输入小数字时,我的代码可以正常工作,例如 (5,6,7)。使用 Pycharm 作为我的 IDE。
【问题讨论】:
-
25, 4556, 5544不是有效的三角形。两个较短的边不够长。这就像试图制作一个三角形,其中一边的长度为 1,第二边的长度为 3,第三边的长度为 1000。这显然不起作用。 -
你能画出这样的三角形吗?
-
@ParasKumar:检查我的答案。如果有帮助,don't forget to accept it :)
-
@OliverCharlesworth 给我一些 4D 方格纸...
标签: python python-3.x area complex-numbers