-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-square.py
More file actions
35 lines (32 loc) · 977 Bytes
/
Copy path4-square.py
File metadata and controls
35 lines (32 loc) · 977 Bytes
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
#!/usr/bin/python3
class Square:
""" A class that defines a square by its size
"""
def __init__(self, size=0):
""" Method to initialize the square object
"""
if not isinstance(size, int):
raise TypeError("size must be an integer")
elif size < 0:
raise ValueError("size must be >= 0")
else:
self.__size = size
def area(self):
""" Method that returns the square are of the object
"""
return (self.__size ** 2)
@property
def size(self):
""" Method to returns the size value
"""
return self.__size
@size.setter
def size(self, value):
""" Method to set the size value of the square object
"""
if not isinstance(value, int):
raise TypeError("size must be an integer")
elif value < 0:
raise ValueError("size must be >= 0")
else:
self.__size = value