PROGRAM FOR LIBRARY MANAGE
PROJECT CLASS XI A
KRISHNA | PYTHON CODE | January 17, 2025
class Library:
def __init__(self):
self.books = []
def add_book(self, title, author, year):
book = {"Title": title, "Author": author, "Year": year}
self.books.append(book)
print(f'Book "{title}" added successfully!')
def view_books(self):
if not self.books:
print("No books in the library.")
else:
print("\nList of Books in the Library:")
for i, book in enumerate(self.books, start=1):
print(f"{i}. Title: {book['Title']}, Author: {book['Author']}, Year:
{book['Year']}")
def search_book(self, title):
found_books = [book for book in self.books if title.lower() in
book["Title"].lower()]
if found_books:
print("\nSearch Results:")
for i, book in enumerate(found_books, start=1):
print(f"{i}. Title: {book['Title']}, Author: {book['Author']}, Year:
{book['Year']}")
else:
print(f'No books found with title "{title}".')
PAGE 1
def main():
library = Library()
while True:
print("\nLibrary Management System")
print("1. Add Book")
print("2. View Books")
print("3. Search Book")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
title = input("Enter book title: ")
author = input("Enter book author: ")
year = input("Enter year of publication: ")
library.add_book(title, author, year)
elif choice == "2":
library.view_books()
elif choice == "3":
search_title = input("Enter the title to search: ")
library.search_book(search_title)
elif choice == "4":
print("Exiting the Library Management System. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
PAGE 2
OUTPUT
Library Management System
1. Add Book
2. View Books
3. Search Book
4. Exit
Enter your choice (1-4): 1
Enter book title: SUMITA ARORA CLASS 11 CS
Enter book author: SUMITA ARORA
Enter year of publication: NEW EDITIO 2023
Book "SUMITA ARORA CLASS 11 CS " added
successfully!
Library Management System
1. Add Book
2. View Books
3. Search Book
4. Exit
Enter your choice (1-4): 1
Enter book title: CHATTRAPATI SHIVAJI JIVAN PARICHAY
Enter book author: MAPPLE PUBLICATION
Enter year of publication: 2024
Book "CHATTRAPATI SHIVAJI JIVAN PARICHAY"
added successfully!
Library Management System
1. Add Book
PAGE 3
2. View Books
3. Search Book
4. Exit
Enter your choice (1-4): 2
List of Books in the Library:
1. Title: SUMITA ARORA CLASS 11 CS, Author: SUMITHA ARORA ,
Year: NEW EDITION 2023
2. Title: CHATTRAPATI SHIVAJI JIVAN PARICHAY, Author: MAPPLE
PUBLICATION, Year: 2024
PAGE 4