Repository navigation
Expand file tree
/
Copy pathCode.py
More file actions
74 lines (56 loc) · 2.26 KB
/
Copy pathCode.py
File metadata and controls
74 lines (56 loc) · 2.26 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
class Library:
def __init__(self, list, name):
self.booksList = list
self.name = name
self.lendDict = {}
def displayBooks(self):
print(f"We have following books in our library: {self.name}")
for book in self.booksList:
print(book)
def lendBook(self, user, book):
if book not in self.lendDict.keys():
self.lendDict.update({book:user})
print("Lender-Book database has been updated. You can take the book now")
else:
print(f"Book is already being used by {self.lendDict[book]}")
def addBook(self, book):
self.booksList.append(book)
print("Book has been added to the book list")
def returnBook(self, book):
self.lendDict.pop(book)
if __name__ == '__main__':
harry = Library(['PythonProgramming', 'IGKAI', 'C#', 'C++ Basics', 'DBMS','Operting System'], "Harshdeep's")
while(True):
print(f"Welcome to the {harry.name} library. Enter your choice to continue")
print("1. Display Books")
print("2. Lend a Book")
print("3. Add a Book")
print("4. Return a Book")
user_choice = input()
if user_choice not in ['1','2','3','4']:
print("Please enter a valid option")
continue
else:
user_choice = int(user_choice)
if user_choice == 1:
harry.displayBooks()
elif user_choice == 2:
book = input("Enter the name of the book you want to lend:")
user = input("Enter your name")
harry.lendBook(user, book)
elif user_choice == 3:
book = input("Enter the name of the book you want to add:")
harry.addBook(book)
elif user_choice == 4:
book = input("Enter the name of the book you want to return:")
harry.returnBook(book)
else:
print("Not a valid option")
print("Press q to quit and c to continue")
user_choice2 = ""
while(user_choice2!="c" and user_choice2!="q"):
user_choice2 = input()
if user_choice2 == "q":
exit()
elif user_choice2 == "c":
continue