Triangle Geometry Functions

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.

PerimeterAreaAnglesEquilateralIsoscelesPythagoras' TheoremHeron's Formula
triangle-perimeter-formulaWrite a function called getPerimeter() that takes three parameters/arguments a, b, c (the length of each side of a triangle).

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
triangle-area-formulaWrite a function called getArea() that takes two parameters/arguments corresponding to the length of the base and of the height of a 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
triangle-angles-formulaWrite a function called getAngle() that takes two parameters/arguments called angle1 and angle2 (the value of two angles in degrees)

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.
triangle-equilateralWrite a function called isEquilateral() that takes three parameters a, b, c (the length of each side of a triangle).

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.
triangle-isoscelesWrite a function called isIsoscles() that takes three parameters a, b, c (the length of each side of a triangle).

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.
triangle-pythagorasWrite a function called getHypotenuse() that takes two parameters/arguments called a and b (the length of two sides of a right-angled triangle).

Your function should calculate and return the length of the third side (the hypotenuse) of the triangle knowing that:
triangle-pythagoras-formula


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.
heron-formula
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.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3.7 / 5. Vote count: 51

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,