class Rectangle: """ Rectangle represented with location and size """ def __init__(self, x1, y1, x2, y2): """ Construct a rectangle based on two corners: (x1, y1) and (x2, y2). :param int x1: :param int y1: :param int x2: :param int 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): """ Calculate the area of the rectangle. :return: the area """ return self.width * self.height def equals(self, another_rectangle): """ Determine if another_rectangle is equivalent to the current rectangle. A rectangle is equivalent if it is at the same x,y location and has the same dimensions. :param Rectangle another_rectangle: another rectangle :return: (bool) True if the other rectangle is equal """ 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): """ Rectangle location and area. :return: (str) representing the rectangle """ 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(10, 20, 0, 0) 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)))