aneliabogeva

Box

Jul 16th, 2019
165
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math as m
  2.  
  3. class Point:
  4. def __init__(self, x, y):
  5. self.x = x
  6. self.y = y
  7.  
  8. def CalcDistance(self,secondPoint):
  9. a = int(m.fabs(self.x - secondPoint.x))
  10. b = int(m.fabs(self.y - secondPoint.y))
  11. result = m.sqrt((a*a)+(b*b))
  12. return result
  13.  
  14. class Box:
  15. def __init__(self,upperLeft,upperRight,bottomLeft,bottomRight):
  16. self.upperLeft = upperLeft
  17. self.upperRight = upperRight
  18. self.bottomLeft = bottomLeft
  19. self.bottomRight = bottomRight
  20. self.width = self.upperLeft.CalcDistance(self.upperRight)
  21. self.height = self.upperLeft.CalcDistance(self.bottomLeft)
  22.  
  23. def CalculatePerimeter(self):
  24. return int((2*self.width) + (2*self.height))
  25.  
  26. def CalculateArea(self):
  27. return int(self.width * self.height)
  28.  
  29. def Print(self):
  30. print(f"Box: {self.width:.0f}, {self.height:.0f}")
  31. print(f"Perimeter: {self.CalculatePerimeter()}")
  32. print(f"Area: {self.CalculateArea()}")
  33.  
  34. while True:
  35. info = input().split(" | ")
  36. if len(info) == 1:
  37. break
  38. p = []
  39. for el in info:
  40. coor = list(map(int,el.split(":")))
  41. p.append(Point(coor[0],coor[1]))
  42.  
  43. box = Box(p[0],p[1],p[2],p[3])
  44. box.Print()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×