CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day03/triangle.py
Views: 729
1
"""
2
判断输入的边长能否构成三角形
3
如果能则计算出三角形的周长和面积
4
5
Version: 0.1
6
Author: 骆昊
7
Date: 2018-02-28
8
"""
9
import math
10
11
a = float(input('a = '))
12
b = float(input('b = '))
13
c = float(input('c = '))
14
if a + b > c and a + c > b and b + c > a:
15
print('周长: %f' % (a + b + c))
16
p = (a + b + c) / 2
17
area = math.sqrt(p * (p - a) * (p - b) * (p - c))
18
print('面积: %f' % (area))
19
else:
20
print('不能构成三角形')
21
22