The Library Management System is a simple Python program that emulates the core functionalities of a library, including adding books, displaying the book catalog, lending books, and returning books. This case study presents a straightforward implementation of a library management system for educational and organizational purposes.
Objectives:
- To create a text-based library management system for managing a collection of books.
- To allow users to add books to the library catalog.
- To provide users with a list of available books.
- To enable users to borrow and return books.
Implementation:
The Library Management System consists of the following components:
- Library Class: The
Library
class serves as the core of the system and contains methods for adding books, displaying the catalog, lending books, and returning books. It uses a dictionary to store book information. - Main Function: The main function initiates the library system and presents a menu to users for performing actions like adding books, displaying books, lending books, and returning books.
print("********** Welcome To Our Library *********** ") class Library: def __init__(self): self.books = {} def add_book(self, title, author): if title in self.books: print("Book already in the library.") else: self.books[title] = author print("Book added successfully.") def display_books(self): if not self.books: print("The library is empty.") else: print("List of books in the library:") for title, author in self.books.items(): print(f"Title: {title}, Author: {author}") def lend_book(self, title, borrower): if title in self.books: if self.books[title] == borrower: print("You have already borrowed this book.") else: self.books[title] = borrower print("Book lent successfully.") else: print("Book not found in the library.") def return_book(self, title, borrower): if title in self.books and self.books[title] == borrower: self.books[title] = None print("Book returned successfully.") else: print("Book not found or not borrowed by you.") def main(): library = Library() while True: print("\nLibrary Management System") print("1. Add a book") print("2. Display books") print("3. Lend a book") print("4. Return a book") print("0. Exit") choice = input("Enter your choice: ") if choice == '1': title = input("Enter the title of the book: ") author = input("Enter the author of the book: ") library.add_book(title, author) elif choice == '2': library.display_books() elif choice == '3': title = input("Enter the title of the book you want to lend: ") borrower = input("Enter your name: ") library.lend_book(title, borrower) elif choice == '4': title = input("Enter the title of the book you want to return: ") borrower = input("Enter your name: ") library.return_book(title, borrower) elif choice == '0': break else: print("Invalid choice. Please enter a valid option.") if __name__ == "__main__": main()
Output:
Case Study Steps:
- Launch the Library Management System.
- The system displays a welcome message, and the main menu is presented to the user.
- Users can choose from the following options:
- Add a Book (Option 1): Users can add books to the library catalog by providing the book’s title and author.
- Display Books (Option 2): Users can view the list of books in the library catalog.
- Lend a Book (Option 3): Users can borrow a book by specifying the title and their name. The system checks for book availability and records the borrower’s name.
- Return a Book (Option 4): Users can return a borrowed book by providing the book’s title and their name. The system verifies the book’s status and updates it.
- Exit (Option 0): Users can exit the library management system.
- The system processes user inputs, executes the chosen action, and provides appropriate feedback.
Conclusion:
The Library Management System presented in this case study offers a simplified way to manage a library’s book catalog. It is suitable for educational purposes and provides the core features necessary for a basic library system, such as adding, displaying, lending, and returning books. Further development could include features like due dates, user authentication, and storing book information in a database for a more comprehensive library management system.