-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheducationaldvdsfunc.py
97 lines (81 loc) · 3.85 KB
/
educationaldvdsfunc.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from model import EducationalDVD
def printInfo(eduDVD):
print(f"ISBN NO:{eduDVD.DVD_No}, Title:{eduDVD.title}, Subject:{eduDVD.subject}, Rental Price:{eduDVD.rental_price}, Available Copies:{eduDVD.copies}")
class eduDVDFunction:
def __init__(self):
self.listOfeduDVDs = []
self.__initialData()
def __initialData(self):
eduDVD1 = EducationalDVD(DVD_No=10, title="Birth of the Solar System", subject="Astronomy", rental_price=2.50, copies=1)
eduDVD2 = EducationalDVD(DVD_No=11, title="Pythagoras Theorem", subject="Math", rental_price=1.00, copies=50)
eduDVD3 = EducationalDVD(DVD_No=12, title="Introduction to Programming", subject="Technology", rental_price=3.00, copies=20)
self.listOfeduDVDs.append(eduDVD1)
self.listOfeduDVDs.append(eduDVD2)
self.listOfeduDVDs.append(eduDVD3)
def add(self):
__DVDNum = input("Enter Educational DVD Number: ").strip().upper()
#Check if user's input is already in the system
matchedData = list(EducationalDVD for EducationalDVD in self.listOfeduDVDs)
for EducationalDVD in matchedData:
if EducationalDVD.CD_no == __DVDNum:
print(f"{__DVDNum} This Educational DVD number is already in this system")
return
else:
pass
__title = input("Enter the title: ")
__subject = input("Subject: ")
try:
__rental_price = float(input("Rental Price: "))
except ValueError:
print("Invalid price entered, terminating...")
return
try:
__copies = int(input("Copies: "))
except ValueError:
print("Invalid copies, Program terminating...")
return
eduDVD = eduDVD(DVD_No=__DVDNum, title=__title, subject=__subject, rental_price=__rental_price, copies=__copies)
self.listOfeduDVDs.append(eduDVD)
print(f"eduDVD added {eduDVD.DVD_No} - {eduDVD.title}")
def remove(self):
__DVDNum = input("Enter Educational DVD Number: ").strip().upper()
matchedData = list(eduDVD for eduDVD in self.listOfeduDVDs if eduDVD.DVD_No == __DVDNum)
for eduDVD in self.listOfeduDVDs:
if __DVDNum == eduDVD.DVD_No:
confirmation = input(f"Remove the {eduDVD.DVD_No} - {eduDVD.title} Y/N: ").upper()
if confirmation == "Y":
for x in matchedData:
self.listOfeduDVDs.remove(x)
print("Item Removed.")
return
else:
print("Operation Cancelled.")
return
else:
print(f"The Educational DVD Number {__DVDNum} not in this system")
return
def lend(self):
__DVDNum = input("Enter Educational DVD Number: ")
__copies = int(input("Enter How Many Copies: "))
matchedData = list(eduDVD for eduDVD in self.listOfeduDVDs if eduDVD.DVD_No == __DVDNum)
for x in matchedData:
x.copies -= __copies
print("Item Lent.")
def recieve(self):
__DVDNum = input("Enter Educational DVD Number: ")
__copies = int(input("Enter received copies: "))
matchedData = list(x for x in self.listOfeduDVDs if x.DVD_No == __DVDNum)
for x in matchedData:
x.copies += __copies
print(f"Item Received with {__copies} Copies")
def displayAll(self):
for x in self.listOfeduDVDs:
printInfo(eduDVD = x)
def available(self):
matchedData = list(x for x in self.listOfeduDVDs if x.copies > 0)
for x in matchedData:
printInfo(eduDVD = x)
def unavailable(self):
matchedData = list(x for x in self.listOfeduDVDs if x.copies == 0)
for x in matchedData:
printInfo(eduDVD = x)