Write a program that accepts the lengths of three sides of a triangle as inputs.

Write a program that accepts the lengths of three sides of a triangle as inputs.

 


Question:


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.


Answer:


Step 1 of 3

Program Plan:

• The program tells whether a triangle is a right angle triangle or not.

• First take all three side of triangle as input from users.

• Check if triangle is right triangle using if and else statement.

• Display the output.

• Sample output is displayed.

Step 2 of 3

Program:

side1=int(input('Enter first side of triangle: ')) #user input side1

side2=int(input('Enter second side of triangle: ')) #user input side2

side3=int(input('Enter third side of triangle: ')) #user input side3

if (side1*side1+side2*side2)==side3*side3 or (side1*side1+side3*side3)==side2*side2 or (side2*side2+side3*side3)==side1*side1: #check if a triangle is right triangle

print('This triangle is a right angled triangle.') #Display output

else:

print('This triangle is not a right angled triangle.') #Display output



Step 3 of 3

Sample Output:



Previous Post
Next Post

post written by:

0 Comments: