In this challenge we will create a library of functions to apply the different formulas based on the geometry of triangles.
For each function, you will need to design the algorithm using either Pseudo-code or a flowchart, implement the function using the Python trinket provided below and use another algorithm to test your function.
Your function should calculate and return the perimeter of this triangle.
Write an algorithm to test your function.
Your algorithm should:
- Ask the user to enter the length of the 3 sides of a triangle,
- Use the getPerimeter() function to retrieve the perimeter of the triangle,
- Display the perimeter of the triangle
Your function should calculate and return the area of this triangle.
Write an algorithm to test your function.
Your algorithm should:
- Ask the user to enter the length of the base and height of a triangle,
- Use the getArea() function to retrieve the area of the triangle,
- Display the area of the triangle
Your function should calculate and return the value of the third angle: (180 – angle1 – angle2)
Write an algorithm to test your function.
Your algorithm should:
- Ask the user to enter the value of two angles in degrees,
- Use the getAngle() function to retrieve the value of the third angle,
- Display this value on screen.
Your function should workout if the triangle is equilateral (if all sides have the same length) and return a Boolean value (True or False) based on its finding.
Write an algorithm to test your function.
Your algorithm should:
- Ask the user to enter the length of the 3 sides of a triangle,
- Use the isEquilateral() function to find out if the triangle is an equilateral triangle,
- Display a relevant message to the end user.
Your function should workout if the triangle is an isosceles triangle (if any two sides have the same length) and return a Boolean value (True or False) based on its finding.
Write an algorithm to test your function.
Your algorithm should:
- Ask the user to enter the length of the 3 sides of a triangle,
- Use the isIsoscles() function to find out if the triangle is an isosceles triangle,
- Display a relevant message to the end user.
Your function should calculate and return the length of the third side (the hypotenuse) of the triangle knowing that:
Write an algorithm to test your function. Your algorithm should:
- Ask the user to enter the length of the 2 sides of a right-angled triangle,
- Use the getyHypotenuse() function to retrieve the value of the hypotenuse of the right–angled triangle,
- Display the value of the Hypotenuse.
Write a function called isRightAngledTriangle(), that takes three parameters a, b and c and works out if the triangle is a right-angled triangle or not. Your function should return a Boolean value (True or False) based on its finding.
Write an algorithm to test your function. Your algorithm should:
- Ask the user to enter the length of the 3 sides of a triangle,
- Use the isRightAngledTriangle() function to find out if the triangle is a right-angled trinagle,
- Display a relevant message to the end-user.
Write a function called getTriangleArea() that takes three parameters/arguments a, b, c (the length of each side of a triangle).
Your function will apply Heron’s formula to calculate and return the area of the triangle.
Write an algorithm to test your function.
Your algorithm should:
- Ask the user to enter the length of the 3 sides of a triangle,
- Use the getTriangleArea() function to retrieve the area of the triangle,
- Display the area of the triangle
Python Code
We have already started the code for you and have completed the function getPerimeter() followed by a short algorithm to test this function.
Your task is to complete this Python script to create and test all the functions mentioned above.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area