class Rectangle: """ An third implementation of a class that represents a rectangle. Attributes ---------- x : (int) bottom-left x-coordinate y: (int) bottom-left y-coordinate width : (int) width height: (int) height Methods ------- area(): (int) returns the area of the rectangle equals(another_rectangle): (bool) returns whether this and another_rectagle are equal """ def __init__(self, x1, y1, x2, y2): """ Creates a two-dimensional rectangle and sets its bottom-left coordinates, width, and height :param x1: (int) first x-coordinate :param y1: (int) first y-coordinate :param x2: (int) second x-coordinate :param y2: (int) second y-coordinate """ # find the bottom-left 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): """ Returns the area of the rectangle :return: (int) the area of the rectangle """ return self.width * self.height def equals(self, another_rectangle): """ returns whether this and another_rectagle are equal :param another_rectangle: (Rectangle) the rectangle to compare this one to :return: (bool) whether this and another_rectagle are 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 __eq__(self, another_rectangle): """ returns whether this and another_rectagle are equal :param another_rectangle: (Rectangle) the rectangle to compare this one to :return: (bool) whether this and another_rectagle are 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): """ Returns string representation of rectangle :return: (str) "Rectangle at (x, y) with area (area)" """ return "Rectangle at (" + str(self.x) + ", " + str(self.y) + \ ") with area: " + str(self.area()) def main(): 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))) print(r1 == r2) print(r1 == r3) print(r1 is r3) if __name__ == "__main__": main()