Pimpri Chinchwad Education Trust’s
Pimpri Chinchwad College of Engineering An
Autonomous Institute
(Affiliated to Savitribai Phule Pune University)
Programming & Problem-Solving Laboratory II
A
Mini-Project Report
On
Console-Based Library
Management System using Python
By
Sr Name PRN Batch
1 Shrivardhan Adarshe 124B1G093 B-2
2 Mohak Godbole 124B1G089 B-2
Submitted On: ________________
Department of Applied Science & Humanities
(Mechanical Engineering)
Pimpri Chinchwad Education Trust’s
Pimpri Chinchwad College of Engineering, Pune - 411044
An Autonomous Institute
(Affiliated to Savitribai Phule Pune University)
November 2023
1
Table of Contents
Sr Topic Page No.
1 Problem Statement 2
2 Algorithm 3
3 Code Details 4
4 Code 5-8
6 Output 9
7 Shared Responsibilities 10
8 References 10
PROBLEM STATEMENT
Libraries, whether physical or digital, require efficient management
systems to keep track of books, patrons, and lending operations. A
Library Management System (LMS) provides a way to manage books,
checkouts, and returns, and ensures that books are not double-checked
out. This system will assist library staff in performing various tasks like
adding books, checking out and returning books, and generating
reports.
2
ALGORITHM
1.Start the program.
2.Define a Book class:
Initialize book details (title, author, ISBN, quantity, checked_out).
Define methods: check_out(), return_book(), available_copies(),
and __str__().
3.Define a Library class:
Initialize a dictionary to store books by ISBN.
Define methods to:
Add book
Remove book
Search books
Check out book
Return book
View inventory
Generate report
4.Create a user interface:
Display a menu with options (Add, Remove, Search, etc.).
Take user input and perform the appropriate operation.
Repeat until user chooses to exit.
5.End the program.
3
Code Details
Parameter Details
Object-Oriented
Programming def, if- else, while, print, return, class, main
(OOP) in Python
Input Variables
Input Variables Data Type
title str
author str
isbn str
quantity int
Output Variables
Function/Method Output Variables
Book.return_book() True / False (bool)
Book.available_copies() available_copies (int)
Book.__str__() Formatted string
main() Menu actions printed
4
CODE
class Book:
def __init__(self, title, author, isbn, quantity):
self.title = title
self.author = author
self.isbn = isbn
self.quantity = quantity
self.checked_out = 0
def check_out(self):
if self.checked_out < self.quantity:
self.checked_out += 1
return True
else:
return False
def return_book(self):
if self.checked_out > 0:
self.checked_out -= 1
return True
else:
return False
def available_copies(self):
return self.quantity - self.checked_out
def __str__(self):
return f"Title: {self.title}, Author:
{self.author}, ISBN: {self.isbn}, Available Copies:
{self.available_copies()}"
5
class Library:
def __init__(self):
self.books = {}
def add_book(self, title, author, isbn, quantity):
if isbn in self.books:
self.books[isbn].quantity += quantity
else:
self.books[isbn] = Book(title, author, isbn,
quantity)
print(f"Book '{title}' added successfully.")
def remove_book(self, isbn):
if isbn in self.books:
del self.books[isbn]
print("Book removed successfully.")
else:
print("Book not found.")
def search_books(self, search_query):
results = [book for book in self.books.values() if
search_query.lower() in book.title.lower() or
search_query.lower() in book.author.lower()]
return results
def check_out_book(self, isbn):
if isbn in self.books:
book = self.books[isbn]
if book.check_out():
print(f"Book '{book.title}' checked out
successfully.")
else:
print(f"Sorry, '{book.title}' is currently
unavailable.")
else:
print("Book not found.")
def return_book(self, isbn):
if isbn in self.books:
book = self.books[isbn]
if book.return_book():
print(f"Book '{book.title}' returned
successfully.")
else:
print(f"Error: This book was not checked out.")
else:
print("Book not found.") 6
def view_inventory(self):
if self.books:
for book in self.books.values():
print(book)
else:
print("No books available in the library.")
def generate_report(self):
total_books = len(self.books)
total_available = sum(book.available_copies() for book
in self.books.values())
total_checked_out = sum(book.checked_out for book in
self.books.values())
print(f"\nLibrary Report:")
print(f"Total books: {total_books}")
print(f"Total available books: {total_available}")
print(f"Total checked-out books: {total_checked_out}")
def display_menu():
print("\n=== Library Management System ===")
print("1. Add Book")
print("2. Remove Book")
print("3. Search Books")
print("4. Check Out Book")
print("5. Return Book")
print("6. View Inventory")
print("7. Generate Report")
print("8. Exit")
def main():
library = Library()
while True:
display_menu()
choice = input("Enter your choice (1-8): ").strip()
if choice == '1':
title = input("Enter book title: ").strip()
author = input("Enter book author: ").strip()
isbn = input("Enter book ISBN: ").strip()
quantity = int(input("Enter quantity: ").strip())
library.add_book(title, author, isbn, quantity)
7
elif choice == '2':
isbn = input("Enter book ISBN to remove: ").strip()
library.remove_book(isbn)
elif choice == '3':
search_query = input("Enter book title or author to
search: ").strip()
results = library.search_books(search_query)
if results:
print("\nSearch Results:")
for book in results:
print(book)
else:
print("No books found.")
elif choice == '4':
isbn = input("Enter book ISBN to check out: ").strip()
library.check_out_book(isbn)
elif choice == '5':
isbn = input("Enter book ISBN to return: ").strip()
library.return_book(isbn)
elif choice == '6':
library.view_inventory()
elif choice == '7':
library.generate_report()
elif choice == '8':
print("Exiting the system...")
break
else:
print("Invalid choice! Please try again.")
if __name__ == "__main__":
main()
8
OUTPUT
=== Library Management System ===
1. Add Book
2. Remove Book
3. Search Books
4. Check Out Book
5. Return Book
6. View Inventory
7. Generate Report
8. Exit
Book 'The Alchemist' added successfully.
Book 'Atomic Habits' added successfully.
Search Results:
Title: The Alchemist, Author: Paulo Coelho, ISBN: 9780061122415, Available
Copies: 5
Book 'The Alchemist' checked out successfully.
Book 'The Alchemist' returned successfully.
Book removed successfully.
Title: Atomic Habits, Author: James Clear, ISBN: 9780735211292, Available
Copies: 7
Library Report:
Total books: 1
Total available books: 7
Total checked-out books: 0
Exiting the system...
11
SHARED RESPONSIBILITIES
1 Shrivardhan 124B1G093 Code
Adarshe
2 Mohak
Godbole 124B1G089 Report
REFERENCES
Geeks for Geeks https://www.geeksforgeeks.org/ site for
learning new functions
13