-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path6-square.py
More file actions
executable file
·60 lines (51 loc) · 1.75 KB
/
Copy path6-square.py
File metadata and controls
executable file
·60 lines (51 loc) · 1.75 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
#!/usr/bin/python3
"""Square class to represent a square"""
class Square():
"""square class with it's size and proper validation"""
def __init__(self, size=0, position=(0, 0)):
""""Initialize data"""
self.size = size
self.position = position
@property
def size(self):
""""get size"""
return self.__size
@property
def position(self):
""""get position"""
return self.__position
@size.setter
def size(self, value):
""""set size"""
if (type(value) is not int):
raise TypeError("size must be an integer")
elif (value < 0):
raise ValueError("size must be >= 0")
else:
self.__size = value
@position.setter
def position(self, value):
""""set position"""
if (not isinstance(value, tuple)):
raise TypeError("position must be a tuple of 2 positive integers")
elif (len(value) != 2):
raise TypeError("position must be a tuple of 2 positive integers")
elif (type(value[0]) is not int) or (type(value[1]) is not int):
raise TypeError("position must be a tuple of 2 positive integers")
elif (value[0] < 0) or (value[1] < 0):
raise TypeError("position must be a tuple of 2 positive integers")
else:
self.__position = value
def area(self):
""""get area of the square"""
return self.size ** 2
def my_print(self):
"""print the square"""
if self.size == 0:
print()
else:
for i in range(self.position[1]):
print("")
for i in range(self.size):
print(" " * self.position[0], end="")
print("#" * self.size)