Question: PYTHON In Part 3, write a small program that will determine if three values, each representing the length of each side of a triangle, form

PYTHON

In Part 3, write a small program that will determine if three values, each representing the length of each side of a triangle, form a right triangle.

Is It Right-Angled?

Define a funtion called is_right_triangle that takes three formal parameters that represent the length of each side of a triangle. Assume the third parameter is the longest side. The function will return the Boolean values either True or False . Remember the Boolean data type is capitalized and is unquoted.

Include the algorithm below as docString with the funciton definition.

Input: a - length of side a; b - length of side b; c - length of side c. Side c has to be the longest side.

Output: True if the sides a , b , and c form a right triangle, otherwise False is returned.

Process:

1. Calculate the sum of sqares for sides a and b and assign the value to a local variable.

2. Calculate the square of side c and assign the value to a local variable.

3. Write an if-statement to compare the two variables from steps 1 & 2. If the two values are equal then return True , otherwise return False .

Test the function a minimum of two times. Once for three values that represent a righttriangle, and another three values that do not represent a right-triangle. To test the function simply print the function's return value: print(is_right_triangle(3, 4 ,5)) .

Print User Friendly Responses

Now that you have a function that can determine whether the lengths of three sides of a triangle make a right-triangle, the values True and False are kind of meaningless by themselves.

Write a function called analyze_triangle() .

Input: no input parameters are required. Use () as the parameter list.

Output: print a formatted statement.

Process:

1. Ask the user two times for the length the shorter sides of the triangle. Example input values could be 2.5, or 3.0.

2. Ask the user for the length of the longest side of the trianlge.

3. Call the function is_right_triangle passing in the required input. Assign the return value to a variable called right_triange .

4. If right_triange is True then print the message:

"The triangle defined by the side lengths of [a], [b], and [c] is a righttriangle.", otherwise print "The triangle, [a], [b], and [c] is a righttriangle." where the values [a], [b], and [c] represents the information collected from the user. You can format the message by doing the following:

message = "The triangle defined by the side lengths of {0}, {1}, and {2} is a right-triangle.".format(a, b, c) - assuming that a , b , c are defined variables. The values 0, 1, and 2 correspond to the position of the arguments in the format method. Thus {0} references the argument a , {1} references the agrument b , and {2} references the argument c .

Test the function by calling it as the last line in the file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!