Using a Rectangle Class in Python
This week’s assignment was about working with classes and objects in Python. I implemented a Rectangle class using object-oriented programming and tested it with several helper functions. Code Procedure: Created a Point class to represent the (x, y) corner of a rectangle. Defined a Rectangle class that stores position, width, and height. Implemented the following helper functions: create_rectangle(x, y, width, height) - creates a new Rectangle instance. str_rectangle(rect) - returns a string representation of the rectangle. shift_rectangle(rect, dx, dy) - modifies the rectangle’s position in place. offset_rectangle(rect, dx, dy) - returns a new rectangle offset from the original. Tested the functions using the example given in the assignment to ensure they worked as expected. This assignment helped me understand how class instances can be passed into and returned from functions, and how methods like __str__ improve output readability. Code: #...