삼각형과 원의 넓이

성규이·2021년 10월 16일
post-thumbnail

학교에서 나온 과제였습니다.

import math

class Triangle:
    def __init__(self, coords):
        self.x1 = coords[0]
        self.y1 = coords[1]
        self.x2 = coords[2]
        self.y2 = coords[3]
        self.x3 = coords[4]
        self.y3 = coords[5]

    def getArea(self):
        a = math.sqrt((self.x2-self.x1)**2 + (self.y2-self.y1)**2)
        b = math.sqrt((self.x3-self.x1)**2 + (self.y3-self.y1)**2)
        c = math.sqrt((self.x2-self.x3)**2 + (self.y2-self.y3)**2)
        s = (a+b+c) / 2
        area = math.sqrt(s*(s-a)*(s-b)*(s-c))
        return area

class Circle:
    def __init__(self, coords):
        self.x1 = coords[0]
        self.y1 = coords[1]
        self.r = coords[2]

    def getArea(self):
        area = self.r * self.r * math.pi
        return area
profile
안녕 눈 코 입 달린 감자야

0개의 댓글