-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-square.py
More file actions
68 lines (62 loc) · 2.14 KB
/
Copy path6-square.py
File metadata and controls
68 lines (62 loc) · 2.14 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
#!/usr/bin/python3
class Square:
""" A class that defines a square by its size
"""
def __init__(self, size=0, position=(0, 0)):
""" Method to initialize the square object
"""
self.size = size
self.position = position
@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")
if value < 0:
raise ValueError("size must be >= 0")
self.__size = value
@property
def position(self):
""" Method that returns the position value
"""
return self.__position
@position.setter
def position(self, value):
""" Method that sets the position value of a square object
"""
if not isinstance(value, tuple):
raise TypeError("position must be a tuple of 2 positive integers")
if len(value) != 2:
raise TypeError("position must be a tuple of 2 positive integers")
if not isinstance(value[0], int):
raise TypeError("position must be a tuple of 2 positive integers")
if not isinstance(value[1], int):
raise TypeError("position must be a tuple of 2 positive integers")
if value[0] < 0 or value[1] < 0:
raise TypeError("position must be a tuple of 2 positive integers")
self.__position = value
def area(self):
""" Method that returns the square are of the object
"""
return (self.__size ** 2)
def my_print(self):
""" Method that prints a # square according
to the size value
"""
if self.size == 0:
print()
else:
for i in range(self.position[1]):
print()
for i in range(0, self.size):
for k in range(self.position[0]):
print(" ", end='')
for j in range(self.size):
print("#", end='')
print()