31. Python Program to read Three sides of a triangle and print the type of the triangle.
How does this program work?
- In this program you are going to learn about how to find the which type of the triangle using its three sides.
-
We can solve this problem by first calculating the side length and then classifying on comparing of side lengths.
- if all sides are equal, triangle will be equilateral.
- if any two sides are equal triangle will be Isosceles otherwise it will be Scalene.
- Now angle can be classified by Pythagoras theorem, if sum of square of two sides is equal to square of the third side, triangle will be right angle.
Here is the code
#Triangle three sides
a = int(input ("Enter the first side of a triangle: "))
b = int (input("Enter the second side of a triangle: "))
c = int(input ("Enter the third side of a triangle: "))
if (a*a) + (b*b) == (c*c) or (b*b) + (c*c) == (a*a) or (c*c) + (a*a) == (b*b):
print("Right angled Triangle")
elif (a == b) and (b == c):
print("Equilateral Triangle")
elif (a==b) or(b==c) or (c==a):
print("Isosceles Triangle")
elif (a!=b and b!=c and c!=a):
print("Scalene")