我是Python的新手,我碰到这个问题的地方:任何人都知道如何计算三角形的面积/周长/高度?
“生成一个程序,可以计算三角形的周长,三角形的面积和三角形的高度从长度三角形的三条边如果三角形的三条边没有定义有效的三角形,则应显示一条消息,指出这不是一个有效的计算,并且该过程应该终止。
任何人都知道如何解决这个问题?这也许很容易,但我是一个新手,所以是
这是我到目前为止有:
a = float(input('Please Enter the First side of a Triangle: '))
b = float(input('Please Enter the Second side of a Triangle: '))
c = float(input('Please Enter the Third side of a Triangle: '))
if a + b >= c and b + c >= a and c + a >= b:
# calculate area and height here
Perimeter = a + b + c
s = (a + b + c)/2
Area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print("\n The Perimeter of Triangle = %.2f" %Perimeter);
print(" The Area of a Traiangle is %0.2f" %Area)
else:
print('Not a valid triangle')
我还是要计算高度。 D
后,你尝试过,所以,这将是容易让人们回答代码示例。 – San
删除'a,b,c = 1,1,1'行并在if语句之前移动三个'input()'行以使其工作。 – MCManuelLP
你可以用sin,cos或tan来获得高度...在python中你可以通过数学包访问这些...('import math') – MCManuelLP