-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inheritance.py
55 lines (37 loc) · 1.38 KB
/
Inheritance.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
51
52
53
54
55
import datetime
#Parent
class LibraryItem:
def __init__(self, Title, Author, ReferenceNum, Loan,):
self.Title = Title
self.Author = Author
self.ReferenceNum = ReferenceNum
self.Loan = Loan
self.Date = datetime.timedelta(weeks=3)
def Output(self):
print("———————————————————————————————————")
print(f"Title: {self.Title}")
print(f"Author: {self.Author}")
print(f"Reference Number: {self.ReferenceNum}")
print(f"Load: {self.Loan}")
print(f"Date: {self.Date}")
#Child Book of Parent LibraryItem
class Book(LibraryItem):
def __init__(self, Title, Author, ReferenceNum, Loan):
super().__init__(Title, Author, ReferenceNum, Loan)
if Loan:
self.Requested = True
def Output(self):
super().Output()
print(f"Requested: {self.Requested}")
#Child CD of Parent LibraryItem
class CD(LibraryItem):
def __init__(self, Title, Author, ReferenceNum, Loan, Genre):
super().__init__(Title, Author, ReferenceNum, Loan)
self.Genre = Genre
def Output(self):
super().Output()
print(f"Genre: {self.Genre}")
MyBook = Book("BookNameHere", "AuthorNameHere", 132, True)
MyCD = CD("RandomCD", "KeweiChen", 6969, False, "Pop")
MyBook.Output()
MyCD.Output()