Lib
Lib
import csv
import os
import datetime
"""
Create classes for books, members, and transactions (checkouts):
"""
class Book:
def __init__(self, book_id, title, author, copies):
self.book_id = book_id
self.title = title
self.author = author
self.copies = copies
class Member:
def __init__(self, member_id, name, contact):
self.member_id = member_id
self.name = name
self.contact = contact
class Transaction:
def __init__(self, member_id, book_id, checkout_date, due_date):
self.member_id = member_id
self.book_id = book_id
self.checkout_date = checkout_date
self.due_date = due_date
"""
Create functions for actions like
adding books, members, and transactions, checking out and returning books, and
displaying reports:
"""
def return_book(book_id):
for transaction in transactions:
if transaction.book_id == book_id:
transactions.remove(transaction)
increment_copies(book_id)
return True
return False
def is_available(book_id):
for book in books:
if book.book_id == book_id and book.copies > 0:
return True
return False
def increment_copies(book_id):
for book in books:
if book.book_id == book_id:
book.copies += 1
def decrement_copies(book_id):
for book in books:
if book.book_id == book_id:
book.copies -= 1
def generate_report():
for transaction in transactions:
member = next(member for member in members if member.member_id ==
transaction.member_id)
book = next(book for book in books if book.book_id == transaction.book_id)
print(f"Member: {member.name}, Book: {book.title}, Due Date:
{transaction.due_date}")
"""
You can implement a command-line interface (CLI) or
a graphical user interface (GUI) to interact with your library management system.
Here's a simple CLI for adding books, members, checking out and returning books,
and generating reports:
"""
while True:
print("Library Management System Menu:")
print("1. Add Book")
print("2. Add Member")
print("3. Checkout Book")
print("4. Return Book")
print("5. Generate Report")
print("6. Exit")
if choice == '1':
book_id = input("Enter Book ID: ")
title = input("Enter Book Title: ")
author = input("Enter Author: ")
copies = int(input("Enter Number of Copies: "))
add_book(book_id, title, author, copies)
elif choice == '2':
member_id = input("Enter Member ID: ")
name = input("Enter Member Name: ")
contact = input("Enter Contact Information: ")
add_member(member_id, name, contact)
elif choice == '3':
member_id = input("Enter Member ID: ")
book_id = input("Enter Book ID: ")
if checkout_book(member_id, book_id):
print("Book successfully checked out.")
else:
print("Book not available or member does not exist.")
elif choice == '4':
book_id = input("Enter Book ID: ")
if return_book(book_id):
print("Book successfully returned.")
else:
print("Book not checked out or does not exist.")
elif choice == '5':
generate_report()
elif choice == '6':
break
else:
print("Invalid choice. Please try again.")
"""
This example provides a basic library management system
with data storage, functions to manage books, members, and transactions,
and a simple CLI for user interaction.
You can expand and customize it further to meet your specific requirements.
"""