-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentlibrary.py
66 lines (51 loc) · 2.26 KB
/
studentlibrary.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
class Library:
def __init__(self, listOfBooks):
self.books = listOfBooks
def displayAvailableBooks(self):
print("The books present in the library are :- ")
for book in self.books:
print(" .) " + book)
def borrowBook(self, bookName):
if bookName in self.books:
print(f"The book {bookName} is issued. Please return within stipulated time period of 2 weeks.")
self.books.remove(bookName)
return True
else:
print(f"The requested book {bookName} is not either not available or it is already been issued to someoe else. Please select another book or wait until your requested book is returned.")
return False
def returnBook(self, bookName):
self.books.append(bookName)
print("The book is returned successfully. We hope you enjoyed reading it.")
class Student:
def __init__(self):
self.bookList = []
def requestBook(self):
self.book = input("Enter the name of the book :- ")
return self.book
def returnBook(self):
self.book = input("Enter the name of the book you want to return :- ")
return self.book
if __name__ == "__main__":
centralLibrary = Library(["C", "C++", "JAVA", "Python", "ML", "Django", "FLask", "mongoDB", "Node.js", "Assembly", "DSA", "Redis"])
student = Student()
while(True):
welcomeMsg = ''' <=======Welcome To Study Library=======>
Please choose an option:
1. Press 1 to get the list of all the books.
2. Press 2 to register for a book.
3. Press 3 to return a book.
4. Press 4 to exit.
'''
print(welcomeMsg)
a = int(input("Enter your choice :- "))
if a == 1:
centralLibrary.displayAvailableBooks()
elif a == 2:
centralLibrary.borrowBook(student.requestBook())
elif a == 3:
centralLibrary.returnBook(student.returnBook())
elif a == 4:
print("Thanks for choosing our library. We hope to see you soon. Have a nice day.")
exit()
else:
print("Sorry to say but you have entered incorrect option. Please choose a correct one.")