-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path6-square.py
More file actions
executable file
·60 lines (51 loc) · 1.78 KB
/
6-square.py
File metadata and controls
executable file
·60 lines (51 loc) · 1.78 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
"""Coordinates of a square"""
class Square:
"""Private instance attribute: size
Instantiation with area and position method """
def __init__(self, size=0, position=(0, 0)):
"""Initializes attribute size """
self.size = size
self.position = position
def area(self):
"""Calculate area of square"""
return (self.__size * self.__size)
@property
def size(self):
"""Getter for square"""
return self.__size
@size.setter
def size(self, value):
"""Initializes attribute size """
if (type(value) is not int):
raise TypeError("size must be an integer")
if value < 0:
raise ValueError("size must be >= 0")
self.__size = value
@property
def position(self):
"""Getter for position"""
return self.__position
@position.setter
def position(self, value):
"""Initializes attribute position"""
if len(value) is not 2:
raise TypeError("position must be a tuple of 2 positive integers")
if (type(value[0]) is not int or value[0] < 0):
raise TypeError("position must be a tuple of 2 positive integers")
if (type(value[1]) is not int or value[1] < 0):
raise TypeError("position must be a tuple of 2 positive integers")
self.__position = value
def my_print(self):
"""Print method"""
if (self.size == 0):
print()
else:
for i in range(self.position[1]):
print()
for j in range(0, self.size):
for e in range(self.position[0]):
print(" ", end="")
for j in range(self.size):
print("#", end="")
print()