circle: added comments related to TH's solution; removed calls to self._radius that bypass setter call.
This commit is contained in:
parent
9c5f9d0c86
commit
fc52fe0fda
|
|
@ -2,6 +2,7 @@ from math import pi
|
|||
|
||||
|
||||
class Circle:
|
||||
# Missing docstring
|
||||
def __init__(self, radius=1):
|
||||
self.radius = radius
|
||||
|
||||
|
|
@ -20,18 +21,19 @@ class Circle:
|
|||
|
||||
@property
|
||||
def diameter(self):
|
||||
return 2 * self._radius
|
||||
return 2 * self.radius
|
||||
|
||||
@diameter.setter
|
||||
def diameter(self, diameter):
|
||||
if diameter < 0:
|
||||
raise ValueError("Diameter cannot be negative")
|
||||
self._radius = diameter / 2
|
||||
self.radius = diameter / 2
|
||||
|
||||
@property
|
||||
def area(self):
|
||||
return pi * self._radius ** 2
|
||||
return pi * self.radius ** 2
|
||||
|
||||
@area.setter
|
||||
def area(self, area):
|
||||
# Not required: property without setter will raise AttributeError when set
|
||||
raise AttributeError("Can't set attribute")
|
||||
|
|
|
|||
Loading…
Reference in a new issue