class Rectangle: def __init__(self, x1, y1, x2, y2): # find the lower left hand corner if x2 < x1: x1, x2 = x2, x1 if y2 < y1: y1, y2 = y2, y1 self.x = x1 self.y = y1 self.width = x2 - x1 self.height = y2 - y1 def area(self): return self.width * self.height def equals(self, another_rectangle): return self.x == another_rectangle.x and \ self.y == another_rectangle.y and \ self.width == another_rectangle.width and \ self.height == another_rectangle.height def __str__(self): return "Rectangle at (" + str(self.x) + ", " + str(self.y) + \ ") with area: " + str(self.area()) r1 = Rectangle(0, 0, 10, 20) r2 = Rectangle(0, -10, 10, 10) r3 = Rectangle(0, 0, 10, 20) print r1 print r2 print r3 print "Is r1 equal to r2? " + str(r1.equals(r2)) print "Is r1 equal to r3? " + str(r1.equals(r3))