Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete class RectangleCollection, which has one list instance variable, rectan

ID: 3698708 • Letter: C

Question

Complete class RectangleCollection, which has one list instance variable, rectangles, that should initially refer to an empty list. Write a method add_rectangle that takes a Rectangle as a parameter and appends it to the rectangles list. Write a method get_same_area_rects that takes a number as a parameter and returns a list of all Rectangles from the rectangles list that have that area. 1 from typing import List class Rectangle: * " A rectangle with a width and height. "E" def _init_(self, w: int, h: int) -> None: "" "Create a new rectangle of width W and height h. >>> r = Rectangle(1, 2) >>> r.width >>> r.height self.width = w self. height = h def get_area(self) -> int: " " " Return the area of this rectangle. >>>r = Rectangle (10, 20) >>> r.get_area() 200 return self.width * self. height class Rectanglecollection: def __init__(self) -> None: >>> rc = Rectanglecollection () >>> rc. rectangles [] IH

Explanation / Answer

class RectangleCollection: def __init__(self) -> None: self.rectangles = [] def add_rectangle(self, r: Rectangle) -> None: self.rectangles.append(r) def get_same_area_rects(self, area: int) -> list: lst = [] for r in self.rectangles: if r.get_area() == area: lst.append(r) return lst

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote