-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrectangle.py
More file actions
159 lines (143 loc) · 3.55 KB
/
rectangle.py
File metadata and controls
159 lines (143 loc) · 3.55 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/python3
'''
Write the class Rectangle that
inherits from Base:
'''
from models.base import Base
class Rectangle(Base):
'''
Class Rectangle inherits from Base
'''
def __init__(self, width, height, x=0, y=0, id=None):
'''
Constructor
'''
super().__init__(id)
self.width = width
self.height = height
self.x = x
self.y = y
@property
def width(self):
'''
Width getter
'''
return self.__width
@width.setter
def width(self, value):
'''
Width setter
'''
if type(value) is not int:
raise TypeError('width must be an integer')
if value <= 0:
raise ValueError('width must be > 0')
self.__width = value
@property
def height(self):
'''
height getter
'''
return self.__height
@height.setter
def height(self, value):
'''
height setter
'''
if type(value) is not int:
raise TypeError('height must be an integer')
if value <= 0:
raise ValueError('height must be > 0')
self.__height = value
@property
def x(self):
'''
x getter
'''
return self.__x
@x.setter
def x(self, value):
'''
x setter
'''
if type(value) is not int:
raise TypeError('x must be an integer')
if value < 0:
raise ValueError('x must be >= 0')
self.__x = value
@property
def y(self):
'''
y getter
'''
return self.__y
@y.setter
def y(self, value):
'''
y setter
'''
if type(value) is not int:
raise TypeError('y must be an integer')
if value < 0:
raise ValueError('y must be >= 0')
self.__y = value
def area(self):
'''
Returns area
'''
return self.width * self.height
def display(self):
'''
Prints Rectangle to
console with #
'''
for col in range(self.y):
print()
for y_axis in range(self.height):
for x_axis in range(self.x):
print(' ', end='')
for row in range(self.width):
print('#', end='')
print()
def update(self, *args, **kwargs):
'''
Allows for variadic args
'''
argc = len(args)
if argc > 0:
try:
self.id = args[0]
self.width = args[1]
self.height = args[2]
self.x = args[3]
self.y = args[4]
except:
pass
else:
if 'id' in kwargs:
self.id = kwargs['id']
if 'width' in kwargs:
self.width = kwargs['width']
if 'height' in kwargs:
self.height = kwargs['height']
if 'x' in kwargs:
self.x = kwargs['x']
if 'y' in kwargs:
self.y = kwargs['y']
def to_dictionary(self):
'''
Pull the parameters out in
the function as a dictionary
'''
return {
'x': self.x,
'y': self.y,
'id': self.id,
'height': self.height,
'width': self.width}
def __str__(self):
'''
String representation
'''
return ('[Rectangle] ({}) {}/{} - {}/{}'.format(
self.id, self.x, self.y, self.width, self.height))