# Here is Coordinate with OO methods for distance and equals. Note that this # class does not follow the Python convention of using __eq__, so == will # still compare addresses of Coordinate instances (in this code we call .equals explicitly) import math class Coordinate: x=0 y=0 def distance(self,point2): # sqrt of (change in x squared + change in y squared) changex=self.x-point2.x changey=self.y-point2.y d = math.sqrt(math.pow(changex,2)+math.pow(changey,2)) return d def equals(self,point2): if ((self.x==point2.x) and (self.y==point2.y)): return True else: return False # note, short hand for above is: # return ((self.x==point2.x) and (self.y==point2.y)) # main program c1 = Coordinate() c1.x=3 c1.y=5 c2 = Coordinate() c2.x=7 c2.y=9 distance = c1.distance(c2) print distance print c1.equals(c2)