Guest User

Untitled

a guest
Oct 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. from math import sqrt
  2.  
  3.  
  4. class Point:
  5. def __init__(self,x_init,y_init):
  6. self.x = x_init
  7. self.y = y_init
  8.  
  9. def shift(self, x, y):
  10. self.x += x
  11. self.y += y
  12.  
  13. def __repr__(self):
  14. return "".join(["Point(", str(self.x), ",", str(self.y), ")"])
  15.  
  16. p1 = Point(10, 3)
  17. p2 = Point(1, 0)
  18.  
  19.  
  20. def distance(a, b):
  21. return sqrt((a.x-b.x)**2+(a.y-b.y)**2)
  22.  
  23. print(p1.x, p1.y, p2.x, p2.y)
  24. print(distance(p1,p2))
  25.  
  26. p2.shift(2,3)
  27.  
  28. print(p2)
Add Comment
Please, Sign In to add comment