Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Part 2. Circle class. 1. 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 . See FAQ notes at the end of this document for more explanation. Think about what needs to happen whenever the radius is modified. It also needs to happen when the Circle instance is created, so keep in mind the DRY principle of Don't Repeat Yourself. 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 ______________________________________________________________________________________________________- 

EXPECTED OUTPUT:

image text in transcribed

from HW5 import Circle >>> circle circle() Circle Circle ( radius=1) >>> print (circle) Circle of radius 1 circle. radius log circle. radius 2 >>> circle.diameter = 3 circle.radius log >>> circle2 = Circle (radius-2) circle2 Circle(radius-2) >circle2. radius log 121 from HW5 import Circle >>> circle circle() Circle Circle ( radius=1) >>> print (circle) Circle of radius 1 circle. radius log circle. radius 2 >>> circle.diameter = 3 circle.radius log >>> circle2 = Circle (radius-2) circle2 Circle(radius-2) >circle2. radius log 121

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

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago

Question

=+ Are there closed-shop requirements or practices?

Answered: 1 week ago