-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-square.py
executable file
·50 lines (40 loc) · 1.05 KB
/
4-square.py
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
#!/usr/bin/python3
"""
This module provides a Square class that defines a square.
Classes:
Square
Functions:
None
Variables:
None
"""
class Square:
"""
an empty class Square that defines a square
Attributes:
__size (int): The size of the square.
Methods:
__init__: Initializes a Square object with a given size parameter
area: Calculates the area of a square
"""
def __init__(self, size=0):
if not isinstance(size, int):
raise TypeError("size must be an integer")
if size < 0:
raise ValueError("size must be >= 0")
self.__size = size
def area(self):
"""
Calculates the area of a square
"""
return (self.__size * self.__size)
@property
def size(self):
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