Brahmarishi Bawra Shanti
Vidya Peeth
PROJECT FILE
Subject Name: Computer Science
Title: Library Management System
Name: Mannat Sharma
Class: 12th ‘B’
Submitted to: Mr. Ankur Gupta
Submission Date: 10-01-2025
ACKNOWLEDGEMENT
I would like to extend my sincere and
heartfelt thanks towards all those who have
helped me in making this project. Without
their active guidance, help, cooperation,
and encouragement, I would not have been
able to present the project on time.
I extend my sincere gratitude to my
Principal Mr. Ashwani Kumar and my
Computer Science Teacher Mr. Ankur Gupta
for their moral support and guidance during
the tenure of my project.
Date: ................
CERTIFICATE
This is to certify that Mannat Sharma
of Class 12th ‘B’ of Brahamarishi Bawra
Shanti Vidya Peeth has completed has
project file under my supervision. He has
taken proper care and shown utmost
sincerity in the completion of this project.
I certify that this project is up to my
expectation and as per the guidelines
issued by CBSE.
_______________ _____________
Teacher’s signature Principal’s signature
_______________
External Examiner’s signature
INDEX
S. NO. TOPIC PAGE
NAME NO.
1. INTRODUCTION 1-5
TO THE
PROGRAM
2. PYTHON 6-10
PROGRAM
3. CREATING 11
DATABASE AND
TABLES IN SQL
4. OUTPUTS WITH 12-17
CHANGES IN SQL
TABLES
5. BIBLIOGRAPHY 18
INTRODUCTION
This program is designed to manage a library's operations, including
adding, updating, and deleting books; adding customers; borrowing
and returning books; and calculating fines for overdue books. It
interacts with a MySQL database to store and retrieve information.
1. Key Components
• Database Connection:
o The code establishes a connection to a MySQL database
named "library" using the mysql.connector library.
• Functions:
o The program utilizes well-defined functions to encapsulate
different library operations:
▪ book(): Adds a new book to the database, including
its ID, title, author, and available copies.
▪ update_book(): Updates the information of an
existing book based on its ID.
▪ delete_book(): Removes a book from the database
based on its ID.
▪ view_books(): Retrieves and displays all books from
the database.
▪ customer(): Adds a new customer to the database,
including their ID, name, and phone number.
▪ borrow_book(): Records a book borrowing event,
updates the book's availability, and records the
transaction details (including borrow and due dates).
▪ return_book(): Records the return of a borrowed
book, updates the book's availability, and calculates
any fines for overdue returns.
▪ calculate_fine(): Calculates and displays fines for
overdue book returns based on the transaction ID.
▪ admin_menu(): Presents an interactive menu to the
admin, allowing them to select and execute various
library operations.
• Data Handling:
o The program uses parameterized SQL queries to prevent
SQL injection vulnerabilities.
o It interacts with the database using the mycursor object to
execute SQL statements.
o Data is fetched from the database using
mycursor.fetchone() and mycursor.fetchall() methods.
• Date and Time:
o The datetime module is used to handle dates and times,
specifically for calculating due dates and fines for overdue
books.
2. Detailed Explanation of Functions
• book():
o Prompts the user for book details (ID, title, author,
copies).
o Executes an INSERT statement to add the book to the
"books" table in the database.
• update_book():
o Prompts the user for the book ID to update.
o Checks if the book ID exists in the database.
o If the book exists, prompts the user for updated
information and executes an UPDATE statement to modify
the book's details.
• delete_book():
o Prompts the user for the book ID to delete.
o Checks if the book ID exists.
o If the book exists, executes a DELETE statement to remove
the book from the database.
• view_books():
o Executes a SELECT statement to retrieve all book records
from the database.
o Iterates through the fetched data and displays each book's
information.
• customer():
o Prompts the user for customer details (ID, name, phone
number).
o Executes an INSERT statement to add the customer to the
"Customers" table.
• borrow_book():
o Prompts the user for transaction ID, customer ID, and
book ID.
o Checks if both customer and book IDs exist in their
respective tables.
o If both exist:
▪ Calculates the due date (14 days from the borrow
date).
▪ Executes an INSERT statement to record the
transaction in the "Transactions" table.
▪ Updates the "available_copies" of the book in the
"books" table.
• return_book():
o Prompts the user for the transaction ID.
o Checks if the transaction ID exists in the "Transactions"
table.
o If the transaction exists:
▪ Records the return date in the "Transactions" table.
▪ Updates the "available_copies" of the book in the
"books" table.
• calculate_fine():
o Prompts the user for the transaction ID.
o Checks if the transaction ID exists.
o If the transaction exists:
▪ Retrieves the due date and return date from the
"Transactions" table.
▪ Calculates the number of overdue days.
▪ Calculates the fine amount (assuming a fine of 0.25
per day).
▪ Updates the "fine" in the "Transactions" table.
▪ Displays the calculated fine for the given transaction.
• admin_menu():
o Displays a menu of available options to the admin.
o Prompts the admin for their choice.
o Calls the corresponding function based on the admin's
choice.
3. Conclusion
This Python program provides a basic framework for managing a
library database. By incorporating the suggested improvements, you
can enhance its functionality, security, and user experience. This can
be a valuable tool for libraries to efficiently manage their book
inventory, customer information, and borrowing/returning
operations.
Python Program
Creating database and tables in SQL to
store data
Outputs with changes in SQL tables
• Adding a new book to the database, including its ID, title,
author, and available copies.
• Table after previous choice
• Updating the information of an existing book based on its ID.
• Table after previous choice
• To delete a book from the database based on its ID.
• Table after previous choice
• To displays all books from the database.
• Adding the customer’s information.
• Table after previous choice.
• Borrowing and returning books.
• Table after previous choice.
• If there is a fine.
Bibliography
• https://www.youtube.com
/watch?v=0GHft_BuYhs
• https://www.youtube.com
/watch?v=GODYXAnBDvc
• https://www.youtube.com
/watch?v=daVqKsdwL-4