``````

In [7]:

from math import pi

``````
``````

In [1]:

class Circle:

@property

if value < 0:

@property
def diameter(self):

@diameter.setter
def diameter(self, value):

@property
def area(self):
return pi * self.radius ** 2

@area.setter
def area(self, value):
raise AttributeError('Area not settable')

# __str__() is not needed, if __repr__ is also having same implementation
# def __str__(self):

def __repr__(self):

``````
``````

In [2]:

c = Circle(5)

``````
``````

``````
``````

In [3]:

c = Circle(-5)

``````
``````

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-ed2ec340d56d> in <module>()
----> 1 c = Circle(-5)

1 class Circle:
4
5     @property

13         if value < 0:
---> 14             raise ValueError("Radius cannot be negative")
16

``````
``````

In [4]:

``````
``````

Out[4]:

5

``````
``````

In [5]:

c.diameter

``````
``````

Out[5]:

10

``````
``````

In [8]:

c.area

``````
``````

Out[8]:

78.53981633974483

``````
``````

In [9]:

c.diameter = 2

``````
``````

``````
``````

In [10]:

``````
``````

Out[10]:

1.0

``````
``````

In [11]:

c.area

``````
``````

Out[11]:

3.141592653589793

``````
``````

In [12]:

``````
``````

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-b4ce01a9f6b5> in <module>()

13         if value < 0:
---> 14             raise ValueError("Radius cannot be negative")
16

``````
``````

In [13]:

c.diameter = -2

``````
``````

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-13-9b9f22b219a2> in <module>()
----> 1 c.diameter = -2

<ipython-input-1-1d9e1d2a9db1> in diameter(self, value)
21     @diameter.setter
22     def diameter(self, value):
---> 23         self.radius = value / 2
24
25     @property

13         if value < 0:
---> 14             raise ValueError("Radius cannot be negative")
16

``````
``````

In [14]:

c.area = 100

``````
``````

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-912a2f133214> in <module>()
----> 1 c.area = 100

<ipython-input-1-1d9e1d2a9db1> in area(self, value)
29     @area.setter
30     def area(self, value):
---> 31         raise AttributeError('Area not settable')
32
33     # __str__() is not needed, if __repr__ is also having same implementation

AttributeError: Area not settable

``````
``````

In [ ]:

``````