Question: class Circle: Class to create Circle objects def __init__(self, radius=1): Circle initializer self.radius = radius @property def area(self): Calculate and return the area of the

class Circle:

"""Class to create Circle objects"""

def __init__(self, radius=1):

"""Circle initializer"""

self.radius = radius

@property

def area(self):

"""Calculate and return the area of the Circle"""

return math.pi * self.radius ** 2

@property

def diameter(self):

"""Calculate and return the diameter of the Circle"""

return self.radius * 2..;@diameter.setter

def diameter(self, diameter):

"""Set the diameter"""

self.radius = diameter / 2

Modify the Circle class given in 3 ways:

I need to implement __str__ and __repr__ methods and add an attribute variable radius_log to the instance.

radius_log is a list to contain radius values that have belonged to the circle, where the last item in the list would be the same as the current value of the radius. In other words, I want you to keep a log of the changes to the radius of the circle

object. Each time the radius changes, add the new value to the list. You will need to make the radius a

property and add a radius "setter" property method.

>>> from HW5 import Circle

>>> circle = Circle()

>>> circle

Circle(radius=1)

>>> circle.radius_log

[1]

>>> circle.radius = 2

>>> circle.diameter = 3

>>> circle

Circle(radius=1.5)

>>> print(circle)

Circle of radius 1.5

>>> circle.radius_log

[1, 2, 1.5]

>>> circle2 = Circle(radius=2)

>>> circle2.radius_log

[2]

>>> circle2.diameter = 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!