Tutorialspoint
Problem
Solution
Submissions

Library Management System

Certification: Advanced Level Accuracy: 33.33% Submissions: 3 Points: 10

Implement a Python class called LibraryManagementSystem that simulates a basic library. The system should allow adding books to the library, borrowing books, returning books, and searching for books by title, author, or ISBN. Each book should have attributes like title, author, ISBN, and availability status.

Example 1
  • Input: library = LibraryManagementSystem()
  • Operations: library.add_book("1984", "George Orwell", "978-0451524935")
  • Operations: library.borrow_book("978-0451524935")
  • Output: "Book '1984' has been borrowed successfully", False
  • Explanation:
    • Step 1: Create a LibraryManagementSystem instance.
    • Step 2: Add a book to the library.
    • Step 3: Borrow the book and return success message.
    • Step 4: Show the book's availability status is now False.
Example 2
  • Input: library = LibraryManagementSystem()
  • Operations: library.add_book("The Great Gatsby", "F. Scott Fitzgerald", "978-0743273565")
  • Operations: library.search_by_author("F. Scott Fitzgerald")
  • Output: [{"title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "isbn": "978-0743273565", "available": True}]
  • Explanation:
    • Step 1: Create a LibraryManagementSystem instance.
    • Step 2: Add a book to the library.
    • Step 3: Search for books by the author.
    • Step 4: Return the matching book information.
Constraints
  • ISBN must be unique for each book.
  • Time Complexity: O(1) for adding books, O(n) for searching where n is the number of books.
  • Space Complexity: O(n) where n is the number of books.
  • The system should handle cases where a book is not found or already borrowed.
Control StructuresFunctions / MethodsDictionaries GoogleDeloitte
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Use a dictionary to store books with ISBN as keys
  • Implement methods for all library operations (add, borrow, return, search)
  • Consider using multiple data structures for efficient searching by different criteria
  • Implement proper validation for operations like borrowing an already borrowed book
  • Consider implementing a waiting list for borrowed books (optional)
  • Use proper error handling and status messages

Steps to solve by this approach:

 Step 1: Create a Book class with title, author, ISBN, and availability status attributes.
 Step 2: Implement a toString method to display book information and availability.
 Step 3: Develop a LibraryManagementSystem class that maintains a collection of books.
 Step 4: Add methods to add new books to the library's collection.
 Step 5: Implement borrow_book method that changes a book's availability status if found and available.
 Step 6: Create return_book method to update availability when borrowed books are returned.
 Step 7: Develop a search function that finds books by matching keywords across title, author, or ISBN.

Submitted Code :