# Area of triangle from 3 coords

I am trying to find the area of a triangle given 3 sets of coordinates. How can I convert the coordinates from an array to pairs (a1, b1), (a2, b2), (a3, b3) and calculate the area of the triangle?

``````def getTriangleArea(x, y):

///What will be the code

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

x_count = int(input().strip())

x = []

for _ in range(x_count):
x_item = int(input().strip())
x.append(x_item)

y_count = int(input().strip())

y = []

for _ in range(y_count):
y_item = int(input().strip())
y.append(y_item)

result = getTriangleArea(x, y)

fptr.write(str(result) + '\n')

fptr.close()
``````

Here’s the code to convert the coordinates from an array to pairs and calculate the area of the triangle:

``````def getTriangleArea(x, y):
a1, b1 = x[0], y[0]
a2, b2 = x[1], y[1]
a3, b3 = x[2], y[2]
area = abs((a1*(b2-b3) + a2*(b3-b1) + a3*(b1-b2))/2)
return area
``````

This code first extracts the x and y coordinates from the input arrays and assigns them to variables a1, b1, a2, b2, a3, and b3. Then it uses the formula for calculating the area of a triangle given the coordinates of its vertices to calculate the area and returns it.