# Area of Triangle with Python

Basic Python Program to Find the Area of a Triangle.

In this article, I will take you through a basic Python program to find the Area of a Triangle using the Python Programming Langauge. Finding the area of a triangle with Python is same as finding it using mathematics.

So let’s see how we can do it with mathematics so that we can easily implement it with Python.

Also, Read – Machine Learning Full Course for free.

## What is the Area of a Triangle?

In general, the term “area” is defined as the occupied region within the boundary of a flat object or figure. The measurement is made in square units, the standard unit being the square meter (m2). For the calculation of the area, there are predefined formulas for squares, rectangles, circles, triangles, etc. In this article, we’ll learn the area of ​​triangle formulas for different types of triangles, along with some sample problems.

The area of ​​a triangle is defined as the total region bounded by the three sides of a particular triangle. It is equal to half the base times the height, i.e. A = 1/2 × b × h.

## Area of Triangle with Python

Now you must be well aware of what is area and how to find the area in mathematics. Now let’s see how can we find it by using the Python programming language.

To find the area with Python programming language we need 4 variables. 3 variables for storing the values of 3 sides either by taking a user input or simply storing a variable.

Then we need a new variable for storing the previous three variables with the mathematical formula of area of a triangle. But to find the area of a triangle we also need to find the semi- perimeter of a triangle so we need to have one more variable.

Now let’s get into the coding part to write a python program to find the area and semi-perimeter of a triangle:

```.wp-block-code {
border: 0;
padding: 0;
}

.wp-block-code > div {
overflow: auto;
}

.hljs {
box-sizing: border-box;
}

.hljs.shcb-code-table {
display: table;
width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
color: inherit;
display: table-row;
width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
white-space: pre;
}

.wp-block-code code.hljs.shcb-wrap-lines {
white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
border-spacing: 0;
counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
padding-left: 0.75em;
}

.hljs.shcb-line-numbers .shcb-loc::before {
border-right: 1px solid #ddd;
content: counter(line);
display: table-cell;
padding: 0 0.75em;
text-align: right;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: 1%;
}
```a = 5
b = 7
c = 10

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)``````
`The area of the triangle is 16.25`

I hope you liked this article on how to write a program to find the area and semi-perimeter of a triangle with Python. Feel free to ask your valuable questions in the comments section below.