CS PROJECT
CS PROJECT
JOHN’S PUBLIC
SCHOOL
Computer Science Project
LIBRARY MANAGEMENT SYSTEM
NAME : VANSHIKA
CLASS : XII
SECTION : A
ROLL NO. :
SUBJECT : Computer Science
SUBMITTED TO : Mr. Jwala Prasad
INDEX
External
ACKNOWLEDGEMENT
TABLE: Books
TABLE: MEMBERS
TABLE: issuedbooks
SOURCE CODE
import mysql.connector
print("##############################################")
print("# #")
print("# WELCOME TO LIBRARY MANAGEMENT SYSTEM #")
print("# #")
print("##############################################")
def connect_to_db():
conn= mysql.connector.connect(
host="localhost",
return conn
connect_to_db()
def test_connection():
conn= connect_to_db()
cursor= conn.cursor()#pointer that allows to execute sql queries
and fetch data from database
print(row)
conn.close()
test_connection()
print(" ")
print("~~~~~~~~~~~~~Add Books~~~~~~~~~~~~")
print(" ")
def add_books():
conn = connect_to_db()
cursor = conn.cursor()
while True:
title = input("Enter book title: ")
author = input("Enter author: ")
quantity = int(input("Enter quantity: "))
conn.commit()
print("Book added successfully!")
print(" ")
print("`````^.^````^.^````^.^``````")
print(" ")
# Ask if the user wants to add more books
more_books = input("Do you want to add another book? (yes/no):
")
if more_books.lower() != 'yes':
break
conn.close()
add_books()
print(" ")
print("~~~~~~~~~~~~~Search Book~~~~~~~~~~~~~")
print(" ")
def search_book():
while True:
title = input("Enter book title to search (or type 'exit' to
stop): ")
if title.lower() == 'exit':
break
conn.close()
search_book()
print(" ")
print("~~~~~~~~~~~~~Issue Book~~~~~~~~~~~~~")
print(" ")
def Total_Books():
conn= connect_to_db()
Total_Books()
def issue_book():
try:
conn = connect_to_db()
cursor = conn.cursor()
if not book:
print("No such book found!")
return #stops further execution
# Check if there are available copies of the book
if book[3] <= 0: # Assuming book[3] is the quantity
print("Sorry, no copies of this book are available for
issuing.")
return
issue_date = input("Enter issue date (YYYY-MM-DD): ")
conn.commit()
print("Book issued successfully!")
except mysql.connector.Error as err:
print(f"Error: {err}")
finally:
conn.close()
issue_book()
print(" ")
print("~~~~~~~~~~~~~return Book~~~~~~~~~~~~~")
print(" ")
def return_book():
conn = connect_to_db()
cursor = conn.cursor()
conn.commit()
print("Book returned successfully!")
conn.close()
return_book()
print(" ")
print("`````^.^^.^^.^``````")
print(" ")
print(" ")
print("~~~~~~~~~~~~~delete Book~~~~~~~~~~~~~")
print(" ")
def delete_book():
conn = connect_to_db()
cursor = conn.cursor()
while True:
book_id = int(input("Enter book ID to delete (or type '0' to
stop): "))
if book_id == 0:
break
if not book:
print("No such book found!")
else: #confirm the deletion
confirm = input(f"Are you sure you want to delete the book
'{book[1]}'? (yes/no): ")
if confirm.lower() == 'yes':
conn.commit()
conn.close()
delete_book()
print(" ")
print("`````^.^^.^^.^``````")
print(" ")
#main menu
def main_menu():
while True:
print("6. Exit")
if choice == 1:
add_books() # Updated function to add multiple books
elif choice == 2:
search_book()
elif choice == 3:
issue_book()
elif choice == 4:
return_book()
elif choice == 5:
delete_book()
elif choice == 6:
print("Exiting the program. ")
break
else:
print("Invalid choice!")
main_menu()
print(" ")
print(" ")
OUTPUT
BIBLIOGRAPHY
• www.google.com
• www.mysql.com
• www.python.org