Good day! I know the name is strange, now I will explain. According to the task, it is necessary to find the area of ​​the rectangle through the triangles of which this 4 square consists (Photo). Using the formula of Gerona, I wrote the following piece of code:

import math n = int(input()) cor = [] for i in range(0,n): cor.append(input()) g = list(map(int,cor[0].split(sep=' '))) so = 0 #Переменная для общей площади for i in range(0, 6, 2): a = math.sqrt((g[2+i]-g[4+i])**2+(g[3+i]-g[5+i])**2) #Длинна сторон a,b,c b = math.sqrt((g[3+i]-g[0])**2+(g[3+i]-g[1])**2) c = math.sqrt((g[2+i]-g[0])**2+(g[3+i]-g[1])**2) p = (a+b+c)/2 #Полупериметр s = math.sqrt(math.fabs(p*(pa)*(pb)*(pc)))#Площадь по формуле Герона so+=s print(so) 

But the wrong area is displayed! PS The first two values ​​in the list are the coordinates of the common vertex point of the triangles. Input example: 1

5 2 2 1 6 1 6 3 2 3

The answer must be equal to 8

[ enter image description here ]

  • What is g1 variable? - Kirill Malyshev
  • Sorry, the editor fixed it on the link. Of course, g [1] - vladF
  • would format the code, and then the eyes break - not many wanting - AlexandrX
  • So I also formatted - vladF

1 answer 1

Why should the answer be 8? Width 5, height 2. Answer 10.

You have input data do not match the picture. Here:

one

5 2 1 1 1 3 6 3 6 1

And you need to enter the point in order.

 import math def length(x1, y1, x2, y2): return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) def square(a, b, c): p = (a + b + c)/2 return math.sqrt(p*(p - a)*(p - b)*(p - c)) n = int(input()) cor = [] for i in range(0,n): cor.append(input()) g = list(map(int,cor[0].split(sep=' '))) so = 0 #Переменная для общей площади for i in range(2, 7, 2): a = length(g[0], g[1], g[i], g[i + 1]) b = length(g[0], g[1], g[i + 2], g[i + 3]) c = length(g[i], g[i + 1], g[i + 2], g[i + 3]) s = square(a, b, c) # Площадь по формуле Герона so+=s #Учитываем последнюю и первую точки a = length(g[0], g[1], g[len(g) - 2], g[len(g) - 1]) b = length(g[0], g[1], g[2], g[3]) c = length(g[len(g) - 2], g[len(g) - 1], g[2], g[3]) s = square(a, b, c) so+=s print(so)