The class below represents a group of shapes. For instance, a group could be a s
ID: 3722344 • Letter: T
Question
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)Explanation / Answer
here is your python class Group with area included : ----------->>>>>>>
class Group:
def __init__(self):
self.c = set()
self.area = 0.0
def add(self,s):
self.c.add(s)
self.area = self.area + s.area()
def move(self,dx,dy):
for s in self.c:
s.move(dx,dy)
def area(self):
return self.area
def __str__(self):
r = "Group With:"
for s in self.c:
r = r + " " + str(s)
r = r + " Total Area : "+self.area;
return r
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.