In: Computer Science
Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle.
Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides.
An example of the program input and proper output format is shown below:
Enter the first side: 3 Enter the second side: 4 Enter the third side: 5 The triangle is a right triangle
Explanation:
Here is the code which takes three sides of a triangle
Then it tries to find in all the three combinations possible, if there are any pythagorean triplet.
if yes, it prints that the triangle is a right angled triangle.
Code:
first = float(input("Enter first side: "))
second = float(input("Enter second side: "))
third = float(input("Enter third side: "))
if ((first**2) == (second**2 + third**2)) or ((second**2) ==
(first**2 + third**2)) or ((third**2) == (second**2 +
first**2)):
print("The triangle is a right triangle")
else:
print("The triangle is not a right triangle")
Output: