Question: Python 3 The class below represents a group of shapes. For instance, a group could be a square, a rectangle, and a triangle. Implement the
Python 3
The class below represents a group of shapes. For instance, a group could be a square, a rectangle, and a triangle. Implement the area method for the Group class. The area of a group is just the total area of the shapes in the group. For the purpose of this assignment, we will not consider cases where shapes overlap, you simply need to add the areas of the shapes in a group independently : class Group: def init__(self): self.c = set() def add (self, s) "Add shape s to group"" self.c.add (s) def move(self, dx, dy) "" "Move by dx and dy"" for s in self.c: s.move (dx, dy) def area(self) return self.S def str self): r = "Group with :" for s in self.c: r-r "In"str (s) return r The following cell should create a new group, and add both our line and rectangle from above to it. The output should look like Group with: Line from (1, 2) to (5, 6) Rectangle at (-2, -3), width 2, height 3 gl = Group ( ) g1.add(1) gl.add (r) print(gl)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
