0% found this document useful (0 votes)
2 views

cs ka project

The document details a project titled 'ONLINE LIBRARY MANAGEMENT' completed by Rupam Das as part of the computer science practical assessment for the academic year 2024-25. It includes a certificate of completion, acknowledgments, an index of contents, and source code for MySQL and Python, outlining the functionalities of the library management system. The project encompasses various operations such as adding, removing, issuing, and returning books, along with viewing available and issued books.

Uploaded by

r78883366
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

cs ka project

The document details a project titled 'ONLINE LIBRARY MANAGEMENT' completed by Rupam Das as part of the computer science practical assessment for the academic year 2024-25. It includes a certificate of completion, acknowledgments, an index of contents, and source code for MySQL and Python, outlining the functionalities of the library management system. The project encompasses various operations such as adding, removing, issuing, and returning books, along with viewing available and issued books.

Uploaded by

r78883366
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

P.

M SHRI KENDRIYA VIDYALAYA


ORDNANCE FACTORY DUM DUM

• Name: RUPAM DAS


• Class: XII A
• Roll: 23
• Board Roll:
• Academic Year: 2024-25
LIBRARY
MANAGEMENT

Group Members:
1.Rupam Das
2.Sargam Ray
3.Subhajit Mandal
4.Tanmoy Ghosh
3
INDEX
Sr No. Particulars Page
No.
1 Certificate 2
2 Acknowledgement 3
3 Modules and 5-6
Functions
4 Source Code (MySQL) 7
5 Source Code (Python) 8-18
6 Outputs and Tables 19-24
7 Bibliography 25

4
Certificate
It is certified that Rupam Das has successfully
completed his project titled, “ONLINE
LIBRARY MANAGEMENT” under the
supervision and guidance of Mrs. Pournomi Sen
in the partial fulfillment of the computer science
practical assessment conducted during the
academic year 2024-25.

Internal Examiner External Examiner

ACKNOWLEDGEMENT
My heartfelt thanks extend to my instructor, Mrs.
Pournomi Sen, for their guiding influence in
achieving the successful outcome of this project.
Their guidance, unwavering encouragement, and
relentless motivation significantly contributed to
every stage of this endeavor.
I also express my sincere gratitude to our principal,
Mr. Arvind Sharma for providing the necessary
support and facilities that enabled me to prepare this
project.
In closing, I would like to acknowledge all who
provided the motivation to persist in this endeavor.
Modules:
import mysql.connector:
By importing this package, we are able to
establish the
connection between SQL and Python.
Functions:
connect():
This function establishes connection between
Python and MySQL
cursor():
It is a special control structure that facilitates
the row-by-row processing of records in the
result set.
The Syntax is:
<cursor object>=<connection object>.cursor()

5
execute():
This function is used to execute the sql query
and retrieve
records using python.
The syntax is:
<cursor object>.execute(<sql query string>)
fetchall():
This function will return all the rows from the
result set in the form of a tuple containing the
records.
fetchone():
This Function will return one row from the
result set in the form of a tuple containing the
records.
commit():
This function provides changes in the
database physically.

6
<SOURCE CODE>
For MySQL:
create database library;
use library;

CREATE TABLE Available_books


( id INT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
subject VARCHAR(50) NOT NULL,
quantity INT NOT NULL );

CREATE TABLE Issued


( id INT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
subject VARCHAR(50) NOT NULL,
s_name VARCHAR(100) NOT NULL,
s_class INT NOT NULL,
s_books INT NOT NULL );

7
#For Python:

#MySql-Python Connection
import mysql.connector
try:
mydb = mysql.connector.connect(host='localhost', user='root',
passwd='1234')
except mysql.connector.Error as err:
print(f"Error: {err}")
exit()
mycursor=mydb.cursor()
print("""
*----------------------------------*
Welcome to Library Management
*----------------------------------*
""")
#Creating Database
mycursor.execute("create database if not exists Library")
mycursor.execute("use Library")
mycursor.execute("create table if not exists Available_Books(id
int,name varchar(25),subject varchar(25),quantity int)")
mycursor.execute("create table if not exists Issued(id int,name
varchar(25),subject varchar(25),s_name varchar(25),s_class
varchar(25),s_books int)")
mycursor.execute("create table if not exists Login(user
varchar(25),password varchar(25))")
mydb.commit()

8
var=0
mycursor.execute("select * from Login")
for i in mycursor:
var=1
if var==0:
mycursor.execute("insert into Login values('user','ng')")
mydb.commit()
#Application of Loops
while True:
print("""
1.Login
2.Exit
""")
var2=int(input("Enter the corresponding number of your choice: "))
if var2==1:
psswd=input("Enter the password: ")
mycursor.execute("select * from login")
for i in mycursor:
t_user,t_pass=i
if psswd==t_pass:
print("""
Login Successful
Welcome!
""")
loop0="no"
while loop0=="no":
print("""
9
Please Choose From the Given Options Below:

*----------------------------*
1.To Add New Books
2.To Remove Any Book
3.To Issue Book To a Student
4.To Return Any Book
5.To View Available Books
6.To View Issued Books
7.Logout
*----------------------------*
""")
ch=int(input("Enter your choice: "))
if ch == 1:
loop1 = "yes"
while loop1 == "yes":
print("Please fill all the details of the Book:")
mycursor.execute("SELECT * FROM Available_Books")
results = mycursor.fetchall()

try:
id = int(input("Enter the Book Id: "))
except ValueError:
print("""
Invalid input! Please enter a valid number
""")
continue
10
name1 = input("Enter the Book Name: ")
subject1 = input("Enter the Subject name: ")
quan1 = int(input("Enter the No. of books to be added: "))

flag = 0
for t_id, t_name, t_subject, t_quan in results:
if t_id == id:
flag = 1
break

if flag == 1:
print("""
Books of Same Id Cannot Exist! Please Choose a
Different Id
""")
loop1 = input("Would you like to add any other book?
(yes or no): ").lower()
if flag==0:
mycursor.execute(
"INSERT INTO Available_Books (id, name, subject,
quantity) VALUES (%s, %s, %s, %s)",
(id, name1, subject1, quan1),
)
mydb.commit()
print("Books Added Successfully!")
loop1 = input("Would you like to add any other book? (yes
or no): ").lower()

11
loop0 = input("Would you like to logout? (yes or no):
").lower()
continue
elif ch == 2:
loop2 = "yes"
while loop2 == "yes":
try:
id = int(input("Enter the ID of the Book to Remove: "))
mycursor.execute("SELECT * FROM Available_Books
WHERE id = %s", (id,))
book = mycursor.fetchone()

if book:
mycursor.execute("DELETE FROM Available_Books
WHERE id = %s", (id,))
mydb.commit()
print("""
Entry Deleted Successfully!
""")
else:
print("""
Book with the following ID does not exist.
""")
except ValueError:
print("Invalid input! Please enter a valid integer ID.")
except mysql.connector.Error as err:
print(f"An error occurred: {err}")

12
loop2 = input("Would you like to remove another book?
(yes or no): ").lower()
loop0=(input("Would you Like to Logout? (yes/no): "))
continue
elif ch==3:
loop1="yes"
while loop1=="yes":
try:
id = int(input("Enter the Book Id to Issue: "))
except ValueError:
print("""
Invalid input! Please enter a valid number
""")
continue
s_name=input("Enter the name of the Student to issue to:
")
s_class=input("Enter the Class of the Student: ")
s_number=int(input("Enter the No. of Books to Issue: "))
mycursor.execute("select * from Available_Books where
id='"+str(id)+"'")
flag=0
for i in mycursor:
t_id,t_name,t_subject,t_quan=i
if t_id==id:
flag=1
if flag==1:
quan = t_quan - s_number

13
if t_quan>=1 and t_quan-s_number>=0:
mycursor.execute("insert into Issued
values('"+str(id)+"','"+t_name+"','"+t_subject+"','"+s_name+"','"+s_class+"','
"+str(s_number)+"')")
mycursor.execute("update Available_Books set
quantity='"+str(quan)+"'where id ='"+str(id)+"'")
mydb.commit()
print("""

Books Issued Successfully!

""")
loop1=input("""
Would you like to Issue more Books?
Please Say Yes/No: """).lower()
else:
print("Book not Available")
break
if flag==0:
print("""

Sorry Book with the Given Id does not Exist :(


""")
loop1=input("""
Would You Like to Issue other Books?:
""")
loop0=input("""

14
Would you like to Logout?
Say Yes/No: """).lower()
continue
if loop0=="yes":
print("""
Thank you for using our service! Please come again!
""")
elif ch==4:
loop1="yes"
while loop1=="yes":
try:
id = int(input("Enter the Book Id: "))
except ValueError:
print("""
Invalid input! Please enter a valid number
""")
continue
s_name=input("Enter the Student's Name: ")
s_class=input("Enter the Student's Class: ")
mycursor.execute("select * from Issued")
flag=0
for i in mycursor:
t_id,t_name,t_subject,t_sname,t_sclass,t_books=i
if t_id==id and t_sname==s_name and t_sclass==s_class:
flag=1
if flag==1:

15
mycursor.execute("select * from Available_Books
where id='"+str(id)+"'")
for i in mycursor:
t_id,t_name,t_subject,t_quan=i
quan=t_quan+t_books
mycursor.execute("delete from Issued where
id='"+str(id)+"' and s_name='"+s_name+"' and s_class='"+s_class+"'")
mycursor.execute("update Available_Books set
quantity='"+str(quan)+"' where id='"+str(id)+"'" )
mydb.commit()
print("""
Books Successfully Returned!
""")
loop1=input("""
Would You like to return more Books?
Enter Yes/No:
""").lower()
else:
print("""
That Book is Currently not Issued
""")
loop1=input("""
Would You Like to Return any other Book?
Enter Yes/No)
""").lower()
loop0=input("""
Would you like to Logout?

16
Enter Yes/No:
""").lower()
continue
elif ch==5:
mycursor.execute("SELECT * FROM Available_Books")
print("\nThe Available Books Currently are:\n")
print("{:<5} {:<20} {:<15} {:<10}".format("ID", "NAME",
"SUBJECT", "QUANTITY"))
print("-" * 50)
for i in mycursor:
a, b, c, d = i
print("{:<5} {:<20} {:<15} {:<10}".format(a, b, c, d))
continue

elif ch==6:
mycursor.execute("SELECT * FROM Issued")
print("\nThe Issued Books Currently are:\n")
print("{:<5} {:<20} {:<20} {:<15} {:<15} {:<15}".format("ID",
"NAME", "SUBJECT", "Student Name","Student Class", "Books in Hold"))
print("-" * 100)
for i in mycursor:
a2, b2, c2, d2, e2, f2 = i
print("{:<5} {:<20} {:<20} {:<15} {:<15} {:<15}".format(a2, b2,
c2, d2, e2, f2))
continue
elif ch==7:
print("""

17
Thank you for using our service! Please come again!
""")
break
else:
print("Incorrect Password Access Denied")
break
elif var2==2:
print("""
Thank you for using our service! Please come again!
""")
break
else:
print("Please enter the correct number from the below options")

18
1.Add a book:

2.Remove any book:

19
3.Issue a book

20
4.Return a book

21
5.View Available Books

22
6.View Issued books

7. Exit Program

23
1. Select * from available_books;

2.select * from issued;

24
BIBLIOGRAPHY
1.www.google.com
2.Class 12 Computer Science by Sumita
Arora
3.Class Notes

25

You might also like