Advertisement
SimeonTs

SUPyF Objects and Classes - 01. Distance Between Points

Jul 8th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. """
  2. Objects and Classes
  3. Проверка: https://judge.softuni.bg/Contests/Practice/Index/950#0
  4.  
  5. SUPyF Objects and Classes - 01. Distance Between Points
  6.  
  7. Problem:
  8. 1.  Distance Between Points
  9. Write a method to calculate the distance between two points p1 {x1, y1} and p2 {x2, y2}.
  10. Write a program to read two points (given as two integers) and print the Euclidean distance between them.
  11. Result, needs to be formatted with :.3f
  12.  
  13. Examples:
  14. Input: |Output:|/    Input: |Output:|/    Input:  |Output: |/
  15. 3 4    |5.000  |/    3 4    |2.000  |/    8 -2    |11.402  |/
  16. 6 8    |       |/    5 4    |       |/    -1 5    |        |/
  17. """
  18. import math
  19.  
  20.  
  21. class Point:
  22.     def __init__(self, data):
  23.         self.data = [int(item) for item in data.split()]
  24.         self.x = self.data[0]
  25.         self.y = self.data[1]
  26.  
  27.  
  28. def calculate(d_1, d_2):
  29.     distance = math.sqrt(math.pow(d_1.x - d_2.x, 2) + math.pow(d_1.y - d_2.y, 2))
  30.     return f"{distance:.3f}"
  31.  
  32.  
  33. p1 = Point(input())
  34. p2 = Point(input())
  35.  
  36. print(calculate(p1, p2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement