0% found this document useful (0 votes)
44 views3 pages

Library Management System

The document describes a Library Management System that allows users to add, issue, and return books, as well as view available books. It includes two main classes: Book, which manages individual book details and status, and Library, which manages a collection of books and user interactions. The system features a menu-driven interface for users to perform various actions related to book management.

Uploaded by

Rakesh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views3 pages

Library Management System

The document describes a Library Management System that allows users to add, issue, and return books, as well as view available books. It includes two main classes: Book, which manages individual book details and status, and Library, which manages a collection of books and user interactions. The system features a menu-driven interface for users to perform various actions related to book management.

Uploaded by

Rakesh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

This system allows for adding books, issuing books to users, returning books, and viewing available

books.

class Book:
def __init__(self, book_id, title, author, year, status="Available"):
self.book_id = book_id
self.title = title
self.author = author
self.year = year
self.status = status # Available or Issued

def issue_book(self):
if self.status == "Available":
self.status = "Issued"
print(f"Book '{self.title}' has been issued.")
else:
print(f"Book '{self.title}' is already issued.")

def return_book(self):
if self.status == "Issued":
self.status = "Available"
print(f"Book '{self.title}' has been returned.")
else:
print(f"Book '{self.title}' is not issued.")

def get_book_info(self):
return f"ID: {self.book_id}, Title: {self.title}, Author:
{self.author}, Year: {self.year}, Status: {self.status}"

class Library:
def __init__(self):
self.books = []

def add_book(self, book):


self.books.append(book)

def show_books(self):
if not self.books:
print("No books available in the library.")
else:
print("\n--- Available Books ---")
for book in self.books:
if book.status == "Available":
print(book.get_book_info())

def issue_book(self, book_id):


for book in self.books:
if book.book_id == book_id:
book.issue_book()
return
print(f"Book with ID {book_id} not found.")

def return_book(self, book_id):


for book in self.books:
if book.book_id == book_id:
book.return_book()
return
print(f"Book with ID {book_id} not found.")

# Menu-driven interface
def library_management():
library = Library()

# Adding some books to the library


library.add_book(Book(1, "The Great Gatsby", "F. Scott Fitzgerald",
1925))
library.add_book(Book(2, "To Kill a Mockingbird", "Harper Lee", 1960))
library.add_book(Book(3, "1984", "George Orwell", 1949))
library.add_book(Book(4, "Moby Dick", "Herman Melville", 1851))

while True:
print("\n--- Library Management System ---")
print("1. Show available books")
print("2. Issue a book")
print("3. Return a book")
print("4. Exit")
choice = input("Enter your choice: ")

if choice == '1':
library.show_books()
elif choice == '2':
book_id = int(input("Enter the book ID to issue: "))
library.issue_book(book_id)
elif choice == '3':
book_id = int(input("Enter the book ID to return: "))
library.return_book(book_id)
elif choice == '4':
print("Thank you for using the Library Management System.")
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
library_management()

Explanation:

Classes:

1. Book Class:
o Represents a book with attributes like book_id, title, author, year, and
status (whether it is "Available" or "Issued").
o It has methods issue_book() to issue the book and return_book() to return
it.
o get_book_info() returns the details of the book.
2. Library Class:
o Represents a library which contains a collection of books.
o It has methods to add books (add_book()), show available books
(show_books()), issue books (issue_book()), and return books
(return_book()).

Functionality:

 The system displays a simple menu that allows users to:


1. View Available Books: Lists all books that are currently available.
2. Issue a Book: Allows the user to issue a book by specifying its ID.
3. Return a Book: Allows the user to return a book by specifying its ID.
4. Exit: Exits the program.

Example Output:

--- Library Management System ---


1. Show available books
2. Issue a book
3. Return a book
4. Exit
Enter your choice: 1

--- Available Books ---


ID: 1, Title: The Great Gatsby, Author: F. Scott Fitzgerald, Year: 1925,
Status: Available
ID: 2, Title: To Kill a Mockingbird, Author: Harper Lee, Year: 1960,
Status: Available
ID: 3, Title: 1984, Author: George Orwell, Year: 1949, Status: Available
ID: 4, Title: Moby Dick, Author: Herman Melville, Year: 1851, Status:
Available

--- Library Management System ---


1. Show available books
2. Issue a book
3. Return a book
4. Exit
Enter your choice: 2
Enter the book ID to issue: 1
Book 'The Great Gatsby' has been issued.

--- Library Management System ---


1. Show available books
2. Issue a book
3. Return a book
4. Exit
Enter your choice: 3
Enter the book ID to return: 1
Book 'The Great Gatsby' has been returned.

You might also like