import math
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
class Triangle:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
def get_area(T):
# TODO: 计算三角形T的面积
return 0.5* abs( T.a.x * (T.b.y-T.c.y) + T.b.x * (T.c.y-T.a.y) + T.c.x * (T.a.y-T.b.y) )
"""
给定平面不共线的三个整数点
P₁(x₁, y₁)、P₂(x₂, y₂)、P₃(x₃, y₃)
有向面积(平行四边形的一半):
S = ½ |x₁(y₂−y₃) + x₂(y₃−y₁) + x₃(y₁−y₂)|
记忆口诀:
“对角相乘再相减,和的一半取绝对。”
"""
def main():
x, y = map(int, input().split())
a = Point(x, y)
x, y = map(int, input().split())
b = Point(x, y)
x, y = map(int, input().split())
c = Point(x, y)
T = Triangle(a, b, c)
print("{:.2f}".format(get_area(T)))
if __name__ == "__main__":
main()
__init__ 是 Python 的构造函数(construction 的缩写),作用一句话:
对象一出生就自动执行,用来给这个新对象“贴标签、装属性、做初始化”。
官方文档原话(3.12)
“
__init__is called after the instance is created but before it is returned to the caller.”—— https://docs.python.org/3/reference/datamodel.html#object.__init__
翻译:
“实例已经被创建,还没交出去给你用之前,Python 先帮你跑一遍 __init__。”

京公网安备 11010502036488号