三角形形状及面积计算器
在线三角形形状及面积计算器
想知道你的三角形是直角、锐角还是钝角?想快速计算出它的面积?这款便捷的在线工具可以帮到你!
只需输入三角形的三条边长,工具将自动判断三角形的形状,并计算出它的面积,精确到小数点后两位。
**代码示例 (Python):**pythonimport math
def determine_triangle_type_and_area(a, b, c): if a <= 0 or b <= 0 or c <= 0: return 'ERROR' if a + b <= c or a + c <= b or b + c <= a: return 'ERROR' # 计算三角形的形状 if a2 + b2 == c2 or a2 + c2 == b2 or b2 + c2 == a2: triangle_type = '直角' elif a2 + b2 < c2 or a2 + c2 < b2 or b2 + c2 < a2: triangle_type = '钝角' else: triangle_type = '锐角'
# 计算三角形的面积 s = (a + b + c) / 2 area = math.sqrt(s * (s - a) * (s - b) * (s - c))
return triangle_type, round(area, 2)
获取用户输入a = int(input('请输入第一条边的长度:'))b = int(input('请输入第二条边的长度:'))c = int(input('请输入第三条边的长度:'))
确定三角形的形状并计算面积result = determine_triangle_type_and_area(a, b, c)
if result == 'ERROR': print('ERROR')else: triangle_type, area = result print('三角形的形状:', triangle_type) print('三角形的面积:', area)
使用说明:
- 将代码复制到你的 Python 环境中。2. 运行代码。3. 输入三角形三条边的长度。4. 程序将输出三角形的形状和面积。
快来试试吧!
原文地址: https://www.cveoy.top/t/topic/bH3p 著作权归作者所有。请勿转载和采集!