【发布时间】:2019-05-16 01:08:40
【问题描述】:
这个基于 Python 3 的函数在给定边长 x、y 和 z 的情况下返回三角形是否为直角。我在简化条件语句时遇到问题。这个函数应该检查锐角、直角、钝角、斜角、等腰角和等边角,还是有条件可以跳过?感谢您提供任何反馈。
def right_angled(x, y, z):
"""This function returns if a triangle is or isn't
right-angled given side lengths x, y, and z."""
p = x + y + z #triangle perimeter
a_sym = p / 180 #triangle perimeter divided by 180
one = x * a_sym #angle one
two = y * a_sym #angle two
three = z * a_sym #angle three
if one and two or one and three or two and three == 90:
return "The triangle is right-angled."
elif one and two and three == 180:
return "The triangle is right-angled." #next conditional(s)?
else:
return "The triangle is not right-angled."
print(right_angled(4, 5, 6))
【问题讨论】:
标签: python-3.x if-statement geometry conditional conditional-statements