This Python 3 based function returns if a triangle is or isn't right-angled given side lengths x, y, and z. I'm having an issue simplifying the conditional statement. Should this function check for acute, right, obtuse, scalene, isosceles, and equilateral angles, or are there conditions I can skip? Any feedback is appreciated.
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))
Aucun commentaire:
Enregistrer un commentaire