-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-square.py
More file actions
executable file
·62 lines (49 loc) · 1.7 KB
/
Copy path6-square.py
File metadata and controls
executable file
·62 lines (49 loc) · 1.7 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
#!/usr/bin/python3
"""Defines class Square"""
class Square():
"""Square class
Args:
size: The size of the square
"""
def __init__(self, size=0, position=(0, 0)):
"""Init of an instance of squere.
Args:
size (int): The size of the square
"""
self.__size = size
self.__position = position
@property
def size(self):
return (self.__size)
@size.setter
def size(self, size):
if type(size) is not int:
raise TypeError("size must be an integer")
elif size < 0:
raise ValueError("size must be >= 0")
self.__size = size
@property
def position(self):
return (self.__position)
@position.setter
def position(self, position):
if (type(position) is not tuple) or (len(position) != 2):
raise TypeError("position must be a tuple of 2 positive integers")
elif (type(position[0]) is not int) or (type(position[1]) is not int):
raise TypeError("position must be a tuple of 2 positive integers")
elif (position[0] < 0) or (position[1] < 0):
raise TypeError("position must be a tuple of 2 positive integers")
else:
self.__position = position
def area(self):
"""Give the current square area"""
return (self.__size ** 2)
def my_print(self):
"""Prints in stdout the square with the character #"""
_print = ""
if self.__size != 0:
_print += "\n" * self.position[1]
for i in range(self.size):
_print += " " * self.position[0]
_print += "#" * self.size + ("\n" if i < self.size - 1 else "")
print(_print)