zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python应用-已知三角形的边长求他的面积和周长

Python应用 三角形 面积 已知
2023-09-14 08:57:35 时间

   

"""
已知三角形的边长求他的面积和周长
Author:罗万财
Date:2017-3-3
"""
import math
a=float(input('a='))
b=float(input('b='))
c=float(input('c='))
if a+b>c and a+c>b and b+c>a:
    d=a+b+c 
    e=(a+b+c)/2 
    f=math.sqrt(e*(e-a)*(e-b)*(e-c))
    print('三角形的周长为:'+str(d))
    print('三角形的面积为:%f' % f)
else:
     print('三条变得长度不能构成三角形')
结果:
a=3
b=4
c=5
三角形的周长为:12.0
三角形的面积为:6.000000