-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-square.py
More file actions
47 lines (43 loc) · 1.27 KB
/
Copy path5-square.py
File metadata and controls
47 lines (43 loc) · 1.27 KB
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
#!/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
def my_print(self):
""" Method that prints a # square according
to the size value
"""
if not self.__size:
print()
else:
for i in range(self.__size):
for j in range(self.__size):
print("#", end='')
print()