-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path018_classes_and_objects.py
More file actions
46 lines (33 loc) · 984 Bytes
/
Copy path018_classes_and_objects.py
File metadata and controls
46 lines (33 loc) · 984 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
39
class Square:
def __init__(self, height="0", width="0"):
self.height = height
self.width = width
# create a getter
@property
def height(self):
print("Retrieving the height")
return self.__height
# create a setter
@height.setter
def height(self, value):
if value.isdigit():
self.__height = value
else:
print("Please only enter numbers for the height")
@property
def width(self):
print("Retrieving the width")
return self.__width
# create a setter
@width.setter
def width(self, value):
if value.isdigit():
self.__width = value
else:
print("Please only enter numbers for the width")
def get_area(self):
return int(self.__width) * int(self.__height)
square = Square()
square.height = "10"
square.width = "10"
print("Square Area: ", square.get_area())