Created
July 8, 2012 22:52
-
-
Save jhgaylor/3073304 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point | |
def __init__(self,x,y): | |
self.x = x | |
self.y = y | |
def __str__(self): | |
return self.x + ", " + self.y | |
def __unicode__(self): | |
return self.x + ", " + self.y | |
def __lt__(self, other): | |
if self.x < other.x: | |
return True | |
else: | |
return False | |
def __gt__(self, other): | |
if self.x > other.x: | |
return True | |
else: | |
return False | |
#http://tpc247.blogspot.com/2011/03/how-to-use-python-r-and-ruby-to-find.html | |
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) | |
P = new Point(1,1) | |
Q = new Point(2,2) | |
if P < Q: | |
print P +" is less than " + Q | |
else: | |
print Q +" is less than " + P | |
if P.isLT(Q): | |
print P +" is less than " + Q | |
else: | |
print Q +" is less than " + P |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment