I have the below code...
import math
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
def __str__(self):
return 'Circle of radius {}'.format(self.radius)
def __repr__(self):
return "Circle(radius={})".format(self.radius)
I want to add an attribute radius_log to the instance. It is a list which would contain radius values which have belonged to the circle as well as the current radius value as the last item in the list. The other properties must still work. I know I have to make the radius a property and add a setter property for the radius. Below is an example output...
circle = Circle()
circle
Circle(radius=1)
circle.radius_log
[1]
circle.radius = 2
circle.diameter = 3
circle
Circle(radius=1.5)
circle.radius_log
[1, 2, 1.5]
circle2 = Circle(radius=2)
circle2.radius_log
[2]
Any ideas on how to do this?