""" 已知三角形的邊長求他的面積和周長 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