三角形判断
def is_triangle(a, b, c):
# 判断是否能构成三角形
if a + b > c and a + c > b and b + c > a:
return True
else:
return False
def triangle_type(a, b, c):
# 首先判断是否能构成三角形
if not is_triangle(a, b, c):
return "无法构成三角形"
#判断三角形的形状
'''max_side = max(a, b, c)
if a == max_side:
other_sides = [b, c]
elif b == max_side:
other_sides = [a, c]
else:
other_sides = [a, b]
if max_side ** 2 == (other_sides[0] ** 2) + (other_sides[1] ** 2):
return "直角三角形"
elif max_side ** 2 < (other_sides[0] ** 2) + (other_sides[1] ** 2):
return "锐角三角形"
else:
return "钝角三角形"'''
max_side = max(a, b, c)
if a ** 2 == b ** 2 + c ** 2 or b ** 2 == a ** 2 + c ** 2 or c ** 2 == a ** 2 + b ** 2:
return "直角三角形"
elif a ** 2 > b ** 2 + c ** 2 or b ** 2 > a ** 2 + c ** 2 or c ** 2 > a ** 2 + b ** 2:
return "钝角三角形"
else:
return "锐角三角形"
# 用户输入三个整数
a = int(input("请输入第一个整数作为三角形的边长: "))
b = int(input("请输入第二个整数作为三角形的边长: "))
c = int(input("请输入第三个整数作为三角形的边长: "))
result = triangle_type(a, b, c)
print(result)