Python-100-Days/Day01-15/code/Day03/triangle.py

21 lines
466 B
Python
Raw Normal View History

2018-03-02 00:09:06 +08:00
"""
判断输入的边长能否构成三角形
如果能则计算出三角形的周长和面积
Version: 0.1
Author: 骆昊
Date: 2018-02-28
"""
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:
2019-05-03 21:17:36 +08:00
print('周长: %f' % (a + b + c))
p = (a + b + c) / 2
area = math.sqrt(p * (p - a) * (p - b) * (p - c))
print('面积: %f' % (area))
2018-03-02 00:09:06 +08:00
else:
2019-05-03 21:17:36 +08:00
print('不能构成三角形')