• Create variables to store three sides of a triangle. Check whether it is an equilateral(等边), Isosceles(等腰), scalene (非等边) and right- angled(直角) triangle. Print the results. • Test your code with different inputs.
时间: 2023-06-01 19:03:26 浏览: 227
判断三角形的形状,可以判断出是锐角,钝角,直角,等腰,等边三角形
5星 · 资源好评率100%
side1 = 5
side2 = 5
side3 = 5
if side1 == side2 == side3:
print("Equilateral triangle")
elif side1 == side2 or side2 == side3 or side1 == side3:
print("Isosceles triangle")
else:
print("Scalene triangle")
if side1**2 == side2**2 + side3**2 or side2**2 == side1**2 + side3**2 or side3**2 == side1**2 + side2**2:
print("Right-angled triangle")
else:
print("Not a right-angled triangle")
# Testing with different inputs
side1 = 3
side2 = 4
side3 = 5
if side1 == side2 == side3:
print("Equilateral triangle")
elif side1 == side2 or side2 == side3 or side1 == side3:
print("Isosceles triangle")
else:
print("Scalene triangle")
if side1**2 == side2**2 + side3**2 or side2**2 == side1**2 + side3**2 or side3**2 == side1**2 + side2**2:
print("Right-angled triangle")
else:
print("Not a right-angled triangle")
side1 = 4
side2 = 4
side3 = 6
if side1 == side2 == side3:
print("Equilateral triangle")
elif side1 == side2 or side2 == side3 or side1 == side3:
print("Isosceles triangle")
else:
print("Scalene triangle")
if side1**2 == side2**2 + side3**2 or side2**2 == side1**2 + side3**2 or side3**2 == side1**2 + side2**2:
print("Right-angled triangle")
else:
print("Not a right-angled triangle")
阅读全文