Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Identify ways to improve the reliability of measurement scales.

Answered: 1 week ago

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago