|
| 1 | +class Library: |
| 2 | + def __init__(self, listOfBooks): |
| 3 | + self.books = listOfBooks |
| 4 | + |
| 5 | + def displayAvailableBooks(self): |
| 6 | + print("Books present in this library are: ") |
| 7 | + for book in self.books: |
| 8 | + print(" *" + book) |
| 9 | + |
| 10 | + def borrowBook(self, bookName): |
| 11 | + if bookName in self.books: |
| 12 | + print(f"You have been issued {bookName}. Please keep it safe and return it within 30 days") |
| 13 | + self.books.remove(bookName) |
| 14 | + return True |
| 15 | + else: |
| 16 | + print("Sorry, This book is either not available or has already been issued to someone else. Please wait until the book is available") |
| 17 | + return False |
| 18 | + |
| 19 | + def returnBook(self, bookName): |
| 20 | + self.books.append(bookName) |
| 21 | + print("Thanks for returning this book! Hope you enjoyed reading it. Have a great day ahead!") |
| 22 | + |
| 23 | +class Student: |
| 24 | + def requestBook(self): |
| 25 | + self.book = input("Enter the name of the book you want to borrow: ") |
| 26 | + return self.book |
| 27 | + |
| 28 | + def returnBook(self): |
| 29 | + self.book = input("Enter the name of the book you want to return: ") |
| 30 | + return self.book |
| 31 | + |
| 32 | + |
| 33 | +if __name__ == "__main__": |
| 34 | + centraLibrary = Library(["Algorithms", "Django", "Clrs", "Python Notes"]) |
| 35 | + student = Student() |
| 36 | + # centraLibrary.displayAvailableBooks() |
| 37 | + while(True): |
| 38 | + welcomeMsg = '''\n ====== Welcome to Central Library ====== |
| 39 | + Please choose an option: |
| 40 | + 1. List all the books |
| 41 | + 2. Request a book |
| 42 | + 3. Add/Return a book |
| 43 | + 4. Exit the Library |
| 44 | + ''' |
| 45 | + print(welcomeMsg) |
| 46 | + a = int(input("Enter a choice: ")) |
| 47 | + if a == 1: |
| 48 | + centraLibrary.displayAvailableBooks() |
| 49 | + elif a == 2: |
| 50 | + centraLibrary.borrowBook(student.requestBook()) |
| 51 | + elif a == 3: |
| 52 | + centraLibrary.returnBook(student.returnBook()) |
| 53 | + elif a == 4: |
| 54 | + print("Thanks for choosing Central Library. Have a great day ahead!") |
| 55 | + exit() |
| 56 | + else: |
| 57 | + print("Invalid Choice!") |
| 58 | + |
| 59 | + |
0 commit comments