Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://judge.softuni.bg/Contests/Compete/Index/950#7
- class Point:
- def __init__(self, abscissa, ordinate):
- self.abscissa = abscissa
- self.ordinate = ordinate
- def calculated_distance(self, p2):
- a = abs(self.abscissa - p2.abscissa)
- b = abs(self.ordinate - p2.ordinate)
- c = pow(pow(a, 2) + pow(b, 2), 1 / 2)
- return c
- class Square:
- def __init__(self, ul, ur, bl, br):
- self.upper_left = ul
- self.upper_right = ur
- self.bottom_left = bl
- self.bottom_left = br
- self.w = ul.calculated_distance(ur)
- self.h = ul.calculated_distance(bl)
- self.a = ul.calculated_distance(ur) * ul.calculated_distance(bl)
- self.p = 2 * ul.calculated_distance(ur) + 2 * ul.calculated_distance(bl)
- def perimeter(self):
- return int(self.p)
- def area(self):
- return int(self.a)
- def width(self):
- return int(self.w)
- def height(self):
- return int(self.h)
- entry = input()
- squares = []
- while entry != 'end':
- tmp = entry.split(' | ')
- points = []
- for s in tmp:
- x, y = s.split(':')
- points.append(Point(int(x), int(y)))
- square = Square(points[0], points[1], points[2], points[3])
- print(f'Box: {square.width()}, {square.height()}')
- print(f'Perimeter: {square.perimeter()}')
- print(f'Area: {square.area()}')
- entry = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement