Skip to content

Instantly share code, notes, and snippets.

@jhgaylor
Created July 9, 2012 06:14
Show Gist options
  • Select an option

  • Save jhgaylor/3074496 to your computer and use it in GitHub Desktop.

Select an option

Save jhgaylor/3074496 to your computer and use it in GitHub Desktop.
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return str(self.x) + ", " + str(self.y)
def __lt__(self, other):
if self.x < other.x:
return True
else:
return False
def __eq__(self,other):
if self.x == other.x:
if self.y == other.y:
return True
return False
def __gt__(self, other):
if self.x > other.x:
return True
else:
return False
def isLT(self, other):
if self.x > other.x:
return True
else:
return False
def distance(self, other):
if self.x is none or self.y is none or other.x is none or other.y is none:
raise Exception
else:
return ((self.x-other.x)**2 + (self.y-other.y)**2)**(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment