Heron’s Formula

The Heron’s formula is a famous formula used to calculate the area of a triangle based on the length of its three sides. It is called “Heron’s Formula” (sometimes called Hero’s formula) after Hero of Alexandria who was a Greek Engineer and Mathematician in 10 – 70 AD.

heron-formula

Python Task


Your task is to write a function called calculateTriangleArea(). Your function will:

  • Take three parameters corresponding to the length of the 3 sides of a triangle: a, b and c,
  • Apply Heron’s formula to calculate the area of the triangle,
  • Return the area of the triangle.

You will also then need to create a small program that will:

  • Ask the user to enter the length of the three sides of a triangle,
  • Calculate the area of the triangle using the calculateTriangleArea() function,
  • Output the area of the triangle.

Video Tutorial


Python Code


Test Plan:


Once your code is done, complete the following tests to check it is working as expected:

Test # Input Values (in cm) Expected Output (in cm2) Pass/Fail?
#1 First side: 3
Second side: 4
Third side: 5
Area: 6
#2 First side: 8
Second side: 10
Third side: 12
Area: 39.686
#3 First side: 4
Second side: 8
Third side: 10
Area: 15.199

Extension Task #1


Create some extra functions to calculate the area of a square, of a rectangle and of a disc. Each function will need to accept the relevant parameters needed to calculate the area of the desired shape.

Extension Task #2


Create a menu system, where the user is asked what shapes they would like to calculate the area of before being asked to enter the relevant dimensions.

Did you know?


Illustration of Hero's Aeolipile (Steam Engine)

Illustration of Hero’s Aeolipile (Steam Engine)

Hero published a well-recognized description of a steam-powered device called an aeolipile (sometimes called a “Hero engine”). Among his most famous inventions was a windwheel, constituting the earliest instance of wind harnessing on land.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.6 / 5. Vote count: 25

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

As you found this challenge interesting...

Follow us on social media!

Tagged with: