WAP (Python) to find the area of a triangle whose coordinates of vertices are given - BoiCoder

BoiCoder

Coding Made Easy for All

Breaking

Saturday 12 September 2020

WAP (Python) to find the area of a triangle whose coordinates of vertices are given



Hello everyone, today we are going to find the area of a triangle whose coordinates of vertices are given, using coordinate geometry.

As always, if you want the full program, you can find it at the end of the article. But it would be good if you stay with us as we are going to do this program the best way possible. So be ready with your code editor and code with us!


Overview:

If you are trying to find the area of a triangle whose coordinates of vertices are given then you have to use the following formula to find its area:

* Here, (x1,y1) (x2,y2) and (x3,y3) represent the coordinates of the three vertices respectively.*

Hence in this program, we have to first take input from user in the form of these coordinates, then we have to put them in this expression to calculate the area of the respective triangle.

As I have already told you the crucial steps for this program, you could try to write this program on your own.


Understanding what we need to do:


Here I will tell step wise what you need to do. 

Step 1: Taking input from the user:

Here, in this step, we need the user to give us the values of the coordinates of the vertices. Hence we will ask for each coordinate and store it in a variable. We will also convert the value to float so that we are able to perform calculations with it. 

Here's the code for this step:



Step 2: Finding the area using the formula:

In this step, we will make a variable named 'area' in which we will store the expression to find the area. Then we would convert the area into a string so that we could print out the result to the user. 

The code for this step is:

Hence we have easily found the area of a triangle whose coordinates of vertices were given.

Here's the full code:

And here we come to the end of our beautiful journey where we learnt how to find the area of a triangle whose coordinates of vertices were given. I hope you learnt how to tackle such questions. Coding is all about tackling daily life problems. 

Here's your next challenge

Write a program to find whether the number entered by the user is  a prime number or not. 

So, in the next article we would find the answer to the above problem. Till then keep coding! Also, if you have problem in any coding project, feel free to write it down in the comments section below. We will surely help you out.


Again thanks for reading! Please consider subscribing to our newsletter as we do these coding sessions each week.

Thanks!

No comments:

Post a Comment