Question: Please write the following Python 3 program. Please show all output. Part 2. Circle class. Modify the Circle class given in 3 ways: 2. (a)

Please write the following Python 3 program.

Please show all output.

Part 2. Circle class.

Modify the Circle class given in 3 ways:

2. (a) - (6 pts) implement __str__ and __repr__ methods exactly as shown below.

2 (b) - (25 pts) make the radius a property and add an attribute radius_log that is a list containing radius values that have belonged to the circle, where the last item in the list is the value of the current 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.

Hint: You will need to store the actual radius somewhere as an attribute of the Circle, since the radius will now be a property. I suggest using an attribute named _radius for this. This attribute should only be used in the radius methods, not in any other methods. Note that once you add the radius properties, they apply everywhere, including the other methods inside the class, which is why you need the separate _radius attribute. The two methods for getting and setting the radius should be the only ones to read/modify this attribute. Other methods such as __init__ should only reference self.radius .

EXAMPLE CODE TO MODIFY:

#Part 2

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

Please write the following Python 3 program. Please show all output. Part

EXPECTED OUTPUT:

2. Circle class. Modify the Circle class given in 3 ways: 2.

(c) - (14 pts) Once you have completed parts (a) and (b), modify the Circle class so that it will raise a ValueError if the radius or diameter is set to less than zero.

EXPECTED OUTPUT:

(a) - (6 pts) implement __str__ and __repr__ methods exactly as shown

class Circle: """Class to create Circle objects""" -init-(self, " ""Circle initializer""" self. radius radius def radius=1): property def area (self): " " "Calculate and return thearea 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 dei diameter (selt, diameter): """Set the diameter"" self. radius diameter / 2

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 Databases Questions!