1 def j(): 2 a,b,c=map(float,input('請輸入三角形三條邊的長度,用空格隔開:').split()) 3 if a>0 and b>0 and c>0 and a+b>c and a+c>b and b+c>a: 4 l=a+b+c 5 p=l/2 6 s=p*(p-a)*(p-b)*(p-c)#海倫公式 7 print('三角形的周長:{:.2f}\n三角形的面積:{:.2f}'.format(l,s)) 8 else: 9 print('三角形不成立,請重新輸入') 10 j() 11 j()
