-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path4-square.py
executable file
·49 lines (35 loc) · 1.07 KB
/
4-square.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
"""
4. Access and update private attribute
A class Square that defines a square
"""
class Square:
"""A class that defines a square"""
def __init__(self, size=0):
"""
Define private instance attribute: size
Raise TypeError & ValueError if not int or <0 resp.
"""
if not isinstance(size, int):
raise TypeError('size must be an integer')
if size < 0:
raise ValueError('size must be >= 0')
self.__size = size
@property
def size(self):
"""Function that returns size"""
return self.__size
@size.setter
def size(self, value):
"""
Define private instance attribute: value
Raise TypeError & ValueError if not int or <0 resp.
"""
if not isinstance(value, int):
raise TypeError('size must be an integer')
if value < 0:
raise ValueError('size must be >= 0')
self.__size = value
def area(self):
"""Function that calculates area"""
return (self.__size ** 2)