CODING
import os
FOLDER_PATH = "C:\\LibraryData"
FILE_PATH = os.path.join(FOLDER_PATH, "books.txt")
if not os.path.exists(FOLDER_PATH):
os.makedirs(FOLDER_PATH)
def read_books():
books = []
if os.path.exists(FILE_PATH):
with open(FILE_PATH, "r", encoding="utf-8") as file:
for line in file:
if '|' in line:
title, status = line.strip().split("|")
books.append({"title": title, "status": status})
return books
def write_books(books):
with open(FILE_PATH, "w", encoding="utf-8") as file:
for book in books:
file.write(f"{book['title']}|{book['status']}\n")
def add_book():
title = input("Enter the book name to add: ").strip()
if title:
books = read_books()
for book in books:
if book["title"].lower() == title.lower():
print("This book already exists.")
return
books.append({"title": title, "status": "Available"})
write_books(books)
print(f"'{title}' has been added to the library.")
else:
print("Book name cannot be empty.")
def view_books():
books = read_books()
if books:
print("\nBooks in the Library:")
for idx, book in enumerate(books, 1):
print(f"{idx}. {book['title']} [{book['status']}]")
else:
print("No books found in the library.")
def borrow_book():
books = read_books()
title = input("Enter the book name to borrow: ").strip()
for book in books:
if book["title"].lower() == title.lower():
if book["status"] == "Available":
book["status"] = "Borrowed"
write_books(books)
print(f"You have borrowed '{book['title']}'.")
return
else:
print(f"'{book['title']}' is already borrowed.")
return
print("Book not found.")
def return_book():
books = read_books()
title = input("Enter the book name to return: ").strip()
for book in books:
if book["title"].lower() == title.lower():
if book["status"] == "Borrowed":
book["status"] = "Available"
write_books(books)
print(f"You have returned '{book['title']}'.")
return
else:
print(f"'{book['title']}' is not currently borrowed.")
return
print("Book not found.")
def library_menu():
while True:
print("\n--- Library Management System ---")
print("1. Add Book")
print("2. View Books")
print("3. Borrow Book")
print("4. Return Book")
print("5. Exit")
choice = input("Enter your choice (1-5): ").strip()
if choice == '1':
add_book()
elif choice == '2':
view_books()
elif choice == '3':
borrow_book()
elif choice == '4':
return_book()
elif choice == '5':
print("Exiting the system. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
library_menu()
OUTPUT
SYSTEM SPECIFICATIONS
HARDWARE SPECIFICATIONS
The following is the hardware specification of the system on which the software has been
developed:-
Operating System : Windows 7/10
Machine Used : Pentium Dual Core Processor 2.6 GHz, 2 GB RAM, 500 GB Hard Disk
SOFTWARE SPECIFICATIONS
Front End Used : Python
Backend Used : python