-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chap13_simple_objects.py
49 lines (38 loc) · 991 Bytes
/
Chap13_simple_objects.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
class Shape():
def __init__(self):
pass
def what_am_i(self):
print("I'm a shape")
class Rectangle(Shape):
def __init__(self,w,l):
self.width = w
self.len = l
def calculate_perimeter(self):
return 2*self.width + 2*self.len
class Square(Shape):
def __init__(self,s):
self.side = s
def calculate_perimeter(self):
return 4*self.side
def change_size(self, num):
self.side += num
class Horse():
def __init__(self,name,h,r):
self.name = name
self.height = h
self.rider = r
class Rider():
def __init__(self, name, age):
self.age = age
self.name = name
a_rider = Rider("George", 25)
a_horse = Horse("At",350,a_rider)
print(a_horse.rider.name)
rec = Rectangle(3,6)
print(rec.calculate_perimeter())
rec.what_am_i()
square = Square(5)
print(square.calculate_perimeter())
square.what_am_i()
square.change_size(1)
print(square.calculate_perimeter())