-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path5-square.py
More file actions
executable file
·54 lines (41 loc) · 1.25 KB
/
5-square.py
File metadata and controls
executable file
·54 lines (41 loc) · 1.25 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
#!/usr/bin/python3
# 5-square.py
"""A module that defines a square """
class Square:
"""A class that represents a square"""
def __init__(self, size=0):
"""Initializing this square class
Args:
size: represnets the size of the square defined
Raises:
TypeError: if size is not integer
ValueError: if size is less than zero
"""
if not isinstance(size, int):
raise TypeError('size must be an integer')
if size < 0:
raise ValueError('size must be >= 0')
self.__size = size
@property
def size(self):
"""Retrieves size of square"""
return self.__size
@size.setter
def size(self, value):
if not isinstance(value, int):
raise TypeError('size must be an integer')
if value < 0:
raise ValueError('size must be >= 0')
self.__size = value
def area(self):
"""
Calculate area of the square
Returns: The square of the size
"""
return (self.__size ** 2)
def my_print(self):
"""print the square in # """
if self.__size == 0:
print()
for i in range(self.__size):
print("#" * self.__size)