Question: Python.Circle class uses a Point object as the center. A @classmethod called from_tuple() is needed to allow Circle objects to be created with tuple instead
Python.Circle class uses a Point object as the center. A @classmethod called from_tuple() is needed to allow Circle objects to be created with tuple instead of a Point as the center. A @classmethod called center_from_tuple() is needed for modifying the center of Circle with a tuple.
This is the homework statement for creating from_tuple() and center_from_tuple().


Please help me with modifying the code to implement from_tuple() and center_from_tuple().
The below is the code for class Point
import math class Point: def __init__(self,x=0,y=0): self.x = x self.y = y self.data=[x,y] def __getitem__(self, index): return self.data[index] def __iter__(self): yield self.x yield self.y def __add__(self,other): return Point(self.x+other.x,self.y+other.y) def __mul__(self,n): return Point(self.x*n,self.y*n) def __rmul__(self,n): return Point(n*self.x,n*self.y) def __str__(self): return "Point at ({0}, {1})".format(self.x,self.y) def __repr__(self): return"Point(x={0}, y={1})".format(self.x,self.y) The below is code for class Circle
def __init__(self, center=(0,0), radius=1): Point.__init__(self,center) self.center=center self.radius=radius def __getitem__(self,item): return self.center[item] def __str__(self): return "Circle with center at ({0}, {1}) and radius {2}".format(self.center.x, self.center.y, self.radius) def __repr__(self): return "Circle(center=Point({0}, {1}), radius {2})".format(self.center[0],self.center[1],self.radius) def __add__(self,other): return Circle( Point(self.center.x+other.center.x, self.center.y+other.center.y), self.radius+other.radius) @classmethod def from_tuple(cls, center,radius): return cls(center, radius) @property def center(self): return self._center @center.setter def center(self, center): if not isinstance(center, Point): raise TypeError("The center must be a Point!") self._center = center @property def radius(self): return self._radius @radius.setter def radius(self, radius): if radius Add a @classmethod called from_tuple() to the Circle class that allows Circle objects to be created with a tuple instead of a Point for the center's location. The resultant instance should have a Point as the center just like any other Circle object. Provide the same defaults for missing arguments. center-point = 3, 4 >>> circle = Circle. from-tuple (center-center-point) >>> circle Circle(center-Point (3, 4), radius-1) >>> circle = Circle. from-tuple(center-center-point, radius = 3) >circle Circle(center Point (3, 4), radius 3) >>> circle = Circle. from-tuple() circle Circle(center-Point(0, 0), radius-1) Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
