0% found this document useful (0 votes)
30 views

Library Management System

Uploaded by

hero78590
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Library Management System

Uploaded by

hero78590
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

class LibraryManagementSystem:

def __init__(self):
self.books = [] # List of all books
self.issued_books = {} # Dictionary to track issued books

def add_book(self):
"""Add a new book to the library."""
print("\n--- Add Book ---")
book_id = input("Enter Book ID: ")
title = input("Enter Book Title: ")
author = input("Enter Book Author: ")
self.books.append({"Book ID": book_id, "Title": title, "Author": author})
print("Book added successfully.")

def view_books(self):
"""View all available books in the library."""
if not self.books:
print("\nNo books available in the library.")
return
print("\n--- Available Books ---")
for book in self.books:
print(f"ID: {book['Book ID']}, Title: {book['Title']}, Author:
{book['Author']}")

def issue_book(self):
"""Issue a book to a user."""
print("\n--- Issue Book ---")
if not self.books:
print("No books available to issue.")
return
book_id = input("Enter Book ID to issue: ")
for book in self.books:
if book['Book ID'] == book_id:
user_name = input("Enter the name of the person issuing the book:
")
self.issued_books[book_id] = {
"Book": book,
"Issued To": user_name
}
self.books.remove(book)
print(f"Book '{book['Title']}' issued to {user_name}.")
return
print("Book ID not found.")

def return_book(self):
"""Return a book to the library."""
print("\n--- Return Book ---")
book_id = input("Enter Book ID to return: ")
if book_id in self.issued_books:
book = self.issued_books.pop(book_id)["Book"]
self.books.append(book)
print(f"Book '{book['Title']}' returned successfully.")
else:
print("Book ID not found in issued books.")

def view_issued_books(self):
"""View all issued books."""
if not self.issued_books:
print("\nNo books have been issued.")
return
print("\n--- Issued Books ---")
for book_id, info in self.issued_books.items():
book = info["Book"]
user = info["Issued To"]
print(f"ID: {book_id}, Title: {book['Title']}, Author:
{book['Author']}, Issued To: {user}")

def main_menu(self):
"""Display the main menu and handle user choices."""
while True:
print("\n--- Library Management System ---")
print("1. Add Book")
print("2. View Books")
print("3. Issue Book")
print("4. Return Book")
print("5. View Issued Books")
print("6. Exit")
choice = input("Enter your choice: ")

if choice == '1':
self.add_book()
elif choice == '2':
self.view_books()
elif choice == '3':
self.issue_book()
elif choice == '4':
self.return_book()
elif choice == '5':
self.view_issued_books()
elif choice == '6':
print("Exiting the system. Goodbye!")
break
else:
print("Invalid choice. Please try again.")

# Run the Library Management System


if __name__ == "__main__":
system = LibraryManagementSystem()
system.main_menu()

You might also like