Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. class Point:
  5.     def __init__(self, x, y):
  6.         self.x = x
  7.         self.y = y
  8.  
  9.     @staticmethod
  10.     def calc_distance(point_1, point_2):
  11.         return math.sqrt((point_1.x - point_2.x)**2 + (point_1.y - point_2.y)**2)
  12.  
  13.     def show_info(self):
  14.         return f"{self.x};{self.y}"
  15.  
  16.  
  17. class Box:
  18.     def __init__(self, upper_left: Point, upper_right: Point, bottom_left: Point, bottom_right):
  19.         self.upper_left = upper_left
  20.         self.upper_right = upper_right
  21.         self.bottom_left = bottom_left
  22.         self.bottom_right = bottom_right
  23.  
  24.     def get_width(self):
  25.         width = Point.calc_distance(self.upper_left, self.upper_right)
  26.         return width
  27.  
  28.     def get_height(self):
  29.         h = Point.calc_distance(self.upper_left, self.bottom_left)
  30.         return h
  31.  
  32.     def calc_perimeter(self):
  33.         return self.get_height() * 2 + self.get_width() * 2
  34.  
  35.     def calc_area(self):
  36.         return self.get_width() * self.get_height()
  37.  
  38.     def show_info(self):
  39.         return f"Box: {self.get_width():.0f}, {self.get_height():.0f}\nPerimeter: {self.calc_perimeter():.0f}\nArea: {self.calc_area():.0f}"
  40.  
  41. def create_point(coor):
  42.     x, y = [int(num) for num in coor.split(":")]
  43.     point = Point(x, y)
  44.     return point
  45.  
  46. def create_box(u_l, u_r, b_l, b_r):
  47.     upper_left = create_point(u_l)
  48.     upper_right = create_point(u_r)
  49.     bottom_left = create_point(b_l)
  50.     bottom_right = create_point(b_r)
  51.  
  52.     box = Box(upper_left, upper_right, bottom_left, bottom_right)
  53.     return box
  54.  
  55.    
  56.  
  57.  
  58. data_list = input().split(" | ")
  59. boxes_list = []
  60.  
  61. while not data_list[0] == "end":
  62.     box = create_box(data_list[0], data_list[1], data_list[2], data_list[3])
  63.     boxes_list.append(box)
  64.    
  65.     data_list = input().split(" | ")
  66.  
  67.  
  68. for box in boxes_list:
  69.     print(box.show_info())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement