Advertisement
b0dRy

08. Boxes

Jul 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. # https://judge.softuni.bg/Contests/Compete/Index/950#7
  2.  
  3.  
  4. class Point:
  5.     def __init__(self, abscissa, ordinate):
  6.         self.abscissa = abscissa
  7.         self.ordinate = ordinate
  8.  
  9.     def calculated_distance(self, p2):
  10.         a = abs(self.abscissa - p2.abscissa)
  11.         b = abs(self.ordinate - p2.ordinate)
  12.         c = pow(pow(a, 2) + pow(b, 2), 1 / 2)
  13.         return c
  14.  
  15.  
  16. class Square:
  17.     def __init__(self, ul, ur, bl, br):
  18.         self.upper_left = ul
  19.         self.upper_right = ur
  20.         self.bottom_left = bl
  21.         self.bottom_left = br
  22.         self.w = ul.calculated_distance(ur)
  23.         self.h = ul.calculated_distance(bl)
  24.         self.a = ul.calculated_distance(ur) * ul.calculated_distance(bl)
  25.         self.p = 2 * ul.calculated_distance(ur) + 2 * ul.calculated_distance(bl)
  26.  
  27.     def perimeter(self):
  28.         return int(self.p)
  29.  
  30.     def area(self):
  31.         return int(self.a)
  32.  
  33.     def width(self):
  34.         return int(self.w)
  35.  
  36.     def height(self):
  37.         return int(self.h)
  38.  
  39.  
  40. entry = input()
  41. squares = []
  42.  
  43. while entry != 'end':
  44.     tmp = entry.split(' | ')
  45.     points = []
  46.     for s in tmp:
  47.         x, y = s.split(':')
  48.         points.append(Point(int(x), int(y)))
  49.     square = Square(points[0], points[1], points[2], points[3])
  50.     print(f'Box: {square.width()}, {square.height()}')
  51.     print(f'Perimeter: {square.perimeter()}')
  52.     print(f'Area: {square.area()}')
  53.     entry = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement