Question

In: Computer Science

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

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.

  • Use The triangle is a right triangle. and The triangle is not a right triangle. as your final outputs.

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

Solutions

Expert Solution

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:


Related Solutions

Write a program that asks the user for the lengths of the sides of a rectangle....
Write a program that asks the user for the lengths of the sides of a rectangle. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values to confirm that the calculations are correct. E.g. 3 – 4 - 5 triangle >> 3 X 4 rectangle Then print • The area and perimeter of the rectangle • The length of the diagonal (use the Pythagorean theorem). This question should be...
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides....
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides. Have a user input the length of three sides of a triangle. Allow the user to enter the sides in any order. Determine if the entered sides form a valid triangle. The triangle may not have negative sides. The sum of any two sides must be greater than the third side to form a triangle. Determine if the entered sides are part of a...
(PYTHON) Write aprogram that prompts user to enter three sides of a triangle....
(PYTHON) Write a program that prompts user to enter three sides of a triangle. The program should determine if the three sides can form a triangle. If the three sides can form a triangle, then determine the type of the triangle.There are three types of triangles: Equilateral triangle (all 3 sides are equal) Isosceles triangle (two sides are equal, the third side is of a different length) Scalene triangle (all 3 sides are of different lengths)   The program should...
Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs:...
Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs: a list of time values a list of position values a single time value. Output: a single number which is obtained by numerically differentiating position with respect to time twice (forward difference method) and then interpolating the results based on the third input. Example: time=0:10; position=time.^3; myaccel(time,position,2.8) % should return 22.8
Write a program Write a program whose inputs are three integers, and whose output is the...
Write a program Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 C++ please
Write in C++ Write a program that accepts the names of three political parties and the...
Write in C++ Write a program that accepts the names of three political parties and the number of votes each received in the last mayoral election. Display the percentage of the vote each party received.   Be sure to provide labels (party name) and number-align your output values.
Argument A Since all triangles have three sides, and an isosceles triangle is a triangle, it...
Argument A Since all triangles have three sides, and an isosceles triangle is a triangle, it follows that an isosceles triangle has three sides. Argument a is: inductive/deductive; valid/invalid/strong/weak; sound/unsound/cogent/uncogent? Argument B There is a large crack in Philadelphia's Liberty Bell. From this, we can conclude that there was a defect in the bell's craftsmanship. Argument B is: inductive/deductive; valid/invalid/strong/weak; sound/unsound/cogent/uncogent? Argument C Paleontologists now agree that the Tyrannosaurus Rex was actually a peaceful, plant-eating dinosaur. Therefore, it is probably...
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
Write a program whose inputs are three integers, and whose output is the smallest of the...
Write a program whose inputs are three integers, and whose output is the smallest of the three values
Write a program whose inputs are three integers, and whose output is the smallest of the...
Write a program whose inputs are three integers, and whose output is the smallest of the three values. Use else-if selection and comparative operators such as '<=' or '>=' to evaluate the number that is the smallest value. If one or more values are the same and the lowest value your program should be able to report the lowest value correctly. Don't forget to first scanf in the users input. Ex: If the input is: 7 15 3 the output...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT