Begin21. The coordinates of the three vertices of the triangle are given: \((x_1, y_1)\), \((x_2, y_2)\), \((x_3, y_3)\).
Find its perimeter and area, using the formula for the distance between two points on the plane (see the task Begin20). To find the area of a triangle with sides \(a, b, c\) use the Heron's formula:

\(S = \sqrt{p \cdot (p - a) \cdot (p - b) \cdot (p - c)},\)

where \(p = (a + b + c)/2\) — semiperimeter.

Solution in Python 3:

import numpy as np
import math

def Distance(A,B):
return math.sqrt((A[0] - B[0])**2 + (A[1] - B[1])**2)

x1,x2,x3,y1,y2,y3 = list(np.random.choice(range(-10, 11), 6))
#x1,x2,x3,y1,y2,y3 = [0,3,0,0,0,4]
while (x3-x1)*(y2-y1) == (y3-y1)*(x2-x1):
x1,x2,x3,y1,y2,y3 = list(np.random.choice(range(-10, 11), 6))

print("Vertex A (x1, y1): ({0},{1})".format(x1, y1))
print("Vertex B (x2, y2): ({0},{1})".format(x2, y2))
print("Vertex C (x3, y3): ({0},{1})".format(x3, y3))

d_AB = Distance([x1,y1],[x2,y2])
print("Length AB: ", d_AB)

d_AC = Distance([x1,y1],[x3,y3])
print("Length AC: ", d_AC)

d_BC = Distance([x2,y2],[x3,y3])
print("Length BC: ", d_BC)

p = (d_AB + d_AC + d_BC)/2
print("Semiperimeter: ", p)

S = math.sqrt(p*(p-d_AB)*(p-d_AC)*(p-d_BC))
print("Area: ", S)