Python 判断三角形函数:is_triangle
可以使用三角形的三边长度关系判断是否能够构成三角形。根据三角形的性质,任意两边之和大于第三边,则可以构成三角形。
下面是实现 is_triangle 函数的代码:
def is_triangle(a, b, c):
if a + b > c and a + c > b and b + c > a:
return True
else:
return False
你可以调用这个函数并传入三个数来进行测试,例如:
is_triangle(3, 4, 5) # 返回 True
is_triangle(1, 2, 3) # 返回 False
原文地址: https://www.cveoy.top/t/topic/fkBl 著作权归作者所有。请勿转载和采集!