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

   

"""
已知三角形的边长求他的面积和周长
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

  

posted @ 2018-03-11 22:17  圆柱模板  阅读(4628)  评论(0编辑  收藏  举报