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