-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path5-square.py
More file actions
executable file
·38 lines (31 loc) · 957 Bytes
/
5-square.py
File metadata and controls
executable file
·38 lines (31 loc) · 957 Bytes
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
#!/usr/bin/python3
""" Printing a square"""
class Square:
"""Private instance attribute: size
Instantiation with area method prints squares """
def __init__(self, size=0):
"""Initializes attribute size """
self.__size = size
def area(self):
"""Calculate area of square"""
return (self.__size * self.__size)
@property
def size(self):
"""Setter 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")
elif value < 0:
raise ValueError("size must be >= 0")
else:
self.__size = value
def my_print(self):
for i in range(self.__size):
for j in range(self.__size):
print('#', end="")
print()
if self.size <= 0:
print()