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:
|
class Circle:
|
||||||
|
# Missing docstring
|
||||||
def __init__(self, radius=1):
|
def __init__(self, radius=1):
|
||||||
self.radius = radius
|
self.radius = radius
|
||||||
|
|
||||||
|
|
@ -20,18 +21,19 @@ class Circle:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def diameter(self):
|
def diameter(self):
|
||||||
return 2 * self._radius
|
return 2 * self.radius
|
||||||
|
|
||||||
@diameter.setter
|
@diameter.setter
|
||||||
def diameter(self, diameter):
|
def diameter(self, diameter):
|
||||||
if diameter < 0:
|
if diameter < 0:
|
||||||
raise ValueError("Diameter cannot be negative")
|
raise ValueError("Diameter cannot be negative")
|
||||||
self._radius = diameter / 2
|
self.radius = diameter / 2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def area(self):
|
def area(self):
|
||||||
return pi * self._radius ** 2
|
return pi * self.radius ** 2
|
||||||
|
|
||||||
@area.setter
|
@area.setter
|
||||||
def area(self, area):
|
def area(self, area):
|
||||||
|
# Not required: property without setter will raise AttributeError when set
|
||||||
raise AttributeError("Can't set attribute")
|
raise AttributeError("Can't set attribute")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue