海倫公式
根據(jù)三角形的三條邊長(zhǎng)度a,b,c科贬,計(jì)算三角形的面積S
p = (a + b + c)/2
S^2 = p * (p - a) * (p - b) * (p - c)
海倫公式的Python實(shí)現(xiàn)
#輸入三條變邊長(zhǎng)分別賦值給a,b,c
a,b,c = eval(input("give three number separated by comma:"))
#判斷給定的三條邊是否能組成一個(gè)三角形
while not (a+b>c and a+c>b and b+c>a):
print('pls give 3 nums once again!')
a,b,c = eval(input("give three number separated by comma:"))
p = (a + b + c)/2
area = (p * (p - a) * (p - b) * (p - c)) ** 0.5
print('三角形的面積為:{0:9.3f}'.format(area))