Library Management System Code
Library Management System Code
import numpy as np
import random
books_data = {
"Title": ["Python Basics", "Data Science", "Machine Learning", "AI for Beginners", "Web Development"],
"Author": ["Author A", "Author B", "Author C", "Author D", "Author E"],
"Read_Count": [20, 45, 30, 25, 50] # Random data for most-read books
members_data = {
# Create DataFrames
books_df = pd.DataFrame(books_data)
members_df = pd.DataFrame(members_data)
cart = [] # Initialize cart
# Graph Functions
def plot_bar_chart():
plt.figure(figsize=(10, 6))
plt.ylabel("Quantity", fontsize=12)
plt.xticks(rotation=45, ha='right')
plt.show()
def plot_line_chart():
plt.figure(figsize=(10, 6))
plt.grid()
plt.xticks(rotation=45, ha='right')
plt.show()
def plot_pie_chart():
plt.figure(figsize=(8, 8))
issued_books = members_df["Books_Issued"]
labels = members_df["Name"]
plt.axis('equal')
plt.show()
# Cart Functions
def add_to_cart():
if book_id in books_df["Book_ID"].values:
cart.append(book_id)
else:
else:
if not cart:
else:
print(book_details.to_string(index=False))
def checkout_cart():
if not cart:
return
books_df.at[book_index, "Quantity"] -= 1
def export_to_csv():
books_df.to_csv("books_data.csv", index=False)
members_df.to_csv("members_data.csv", index=False)
def add_book():
global books_df
books_df = pd.concat([
books_df,
], ignore_index=True)
if books_df.empty:
else:
print(books_df)
def main_menu():
while True:
print("10. Exit")
if choice == 1:
add_book()
elif choice == 2:
view_books()
elif choice == 3:
add_to_cart()
elif choice == 4:
view_cart()
elif choice == 5:
checkout_cart()
elif choice == 6:
plot_bar_chart()
elif choice == 7:
plot_line_chart()
elif choice == 8:
plot_pie_chart()
elif choice == 9:
export_to_csv()
break
else:
if __name__ == "__main__":
main_menu()