-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniProject_1.py
More file actions
108 lines (77 loc) · 3.16 KB
/
MiniProject_1.py
File metadata and controls
108 lines (77 loc) · 3.16 KB
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
98
99
100
101
102
103
104
105
106
107
108
dict1= {"Harry potter 1": "None", "Harry potter 2": "Lewis", "Harry potter 3": "harry", "Harry potter 4": "None",
"Elon musk":"None"}
class Library:
def __init__(self,book_name,book_owner):
self.book_name=book_name
self.book_owner=book_owner
def display_book(self):
for key,value in dict1.items():
if value=="None":
return f"The library has:{dict1.keys()}"
def lend_book(self):
if self.book_name not in dict1:
return f"{self.book_name} is not available"
elif (dict1.get(self.book_name) == "None"):
dict1.update({self.book_name: self.book_owner})
return f"You are lending a book called {self.book_name} and was owned by 'no one' and is now owned by '{dict1.get(self.book_name)}'\n"
elif self.book_owner==dict1.get(self.book_name):
return "You already have the book. Please check"
elif(dict1.get(self.book_name)!= "None"):
return f"This book is owned by {dict1.get(self.book_name)}, please wait until returned"
else:
return f"{self.book_name} is not present in the library"
def return_book(self):
if (self.book_name in dict1):
dict1.update({self.book_name:"None"})
return f"Thank you for returning {self.book_name}"
else:return "Please check again wrong input"
def add(self,user):
self.user=user
if self.book_name!=dict1.keys():
dict1.update({self.book_name:"None"})
return f"Thank you for donating {self.book_name} to our collection, {self.user}\nThis is our updated collection: {dict1.keys()}\n"
else:
print("This book is already in our library. Thank you")
print("\t\t\t\t\t\t\t~~~~ Welcome to the Library ~~~~\t\t\t\t\t\t\t\t")
while (True):
import time
z=int(input(print("\nEnter\n1 for viewing our library\n2 for lending a book\n3 for returning a book\n4 for donating a book: \n")))
time.sleep(2)
if z==1:
ansh=Library("None","None")
print(ansh.display_book())
k = input("Do you want to continue (y/n) : ")
if k == "y":
continue
elif k == "n":
exit()
elif z==2:
b=input("Enter book name:\n")
c=input("Enter your name:\n")
ansh=Library(b,c)
print(ansh.lend_book())
k = input("Do you want to continue (y/n) : ")
if k == "y":
continue
elif k == "n":
exit()
elif z==3:
b=input("Enter book name:\n")
c=input("Enter your name:\n")
ansh=Library(b,c)
print(ansh.return_book())
k = input("Do you want to continue (y/n) : ")
if k == "y":
continue
elif k == "n":
exit()
elif z==4:
b = input("Enter book name:\n")
v = input("Enter your name:\n")
ansh = Library(b, v)
print(ansh.add(v))
k = input("Do you want to continue (y/n) : ")
if k == "y":
continue
elif k == "n":
exit()