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

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM