Adobe Scan Dec 16, 2024
Adobe Scan Dec 16, 2024
2 ACKNOWLEDGEMENT (ü)
3. MAIN CODE FOR LIBRARY MANAGEMENT SYSTEM
6 ERRORS
7 BIBLIOGRAPHY
#LIBRARY MANAGEMENT SYSTEM:
import mysql.connector as msc
mydbumsc.connect (host=' localhost',user'root',pas swd='python')
cur=mydb.cursor()
print (***
**********=
** Welcome to Library Management System **
#Creating Database:
cur.execute("create database if not exists 1ibrary_management_system")
cur.execute("use library_management_system")
cur.execute("create table if not exists available_books(id int primary key not
null, name varchar (25) not null, subject varchar (25) not null, quantity int not
null)")
cur.execute("create table if not exists issued _books (id int not null, book_name
varchar(25) not null, book_subject varchar (25) not null,stu name varchar (20e)
primary key not null,stu class varchar (25) not null, date of_ issue date not
null, date of return date not null)")
cur.execute(" create table if not exists login(user varchar(25) not
null, password varchar(25) primary key not null)")
mydb.commit ()
flag=0
cur.execute("select from login")
for i in cur: #if login doesn't have any value, loop will not executel!
flag = 1
if flag==0:
cur.execute("insert into login values('Admin@123', '1234')")
mydb.commit()
#Loop-->Main Working
while True:
print("**
1.Login
2.Exit
if flag!1:
print ("Please enter the correct id as per the available
books !! ")
else:
if t_quant>e:
S nameminput ("Enter student name : ")
S_class=input("Enter student class: ")
s_doi=input("Enter date of issue : ")
s_dor=input ("Enter date of return : ")
cur.execute("insert into issued books
values(" "*str(b_id) +"',*"+t_name+"',* "*t_sutb+"', *"*s_name+","+s_class+", *"+s
-doi+"', ""*s_dor+"")")
quan=t_quant-1
cur.execute("update available_books set
quantity="*str(quan) +" where id="+str(b_id)+"*")
mydb.commit ()
print ("Book issued successfully !")
else:
Print already I Please wait
until they are returned or issue
("BOOKS a
are 1ssued
nother book 1")
elif chmu4: #Returning Books
b_id=int (input ("Enter id of the book to be returned : "))
sname=input ("Enter name of the student who issued the book
:")
flag-0
t_id=0
t_name=e
t quant=0
cl=0
cur.execute("select distinct id from issued books order by
id")
for i in cur:
if int(i[e]) ==b_id:
t id=int(i[e])
flag+=1
if flagu=0:
print ("No such book is issued 1")
else:
cur.execute("select stu_name from available_books
A,issued books I where A.id-*"+str(t_id)+"* and A.id-I.id and
I.stu_name=*"+sname*")
for i in cur:
t_name=str (i[®])
Cec+1
if cl=0:
cur.execute("select quantity from available_books
where id="*str (t_id)+*m)
for j in cur:
t_quant=int (j[0])
c1+=1
if c1!=0:
quant=t_quant+1
cur.execute("update available_books set
quantity=*"+str(quant)+" where id="+str(t id)+" *)
cur.execute("delete from issued books where
id="+str(t_id)+"* and stu_name "*t_name+"*")
mydb.comnit ()
print ("Book returned successfully !!")
else:
print ("No such student has issued this book ! !")
elif chm=5: #Display Books
print ("ID, NAME, SUBJECT, QUANTITY")
cur.execute("select from available_books")
a=cur.fetchall()
for i in a:
print (i)
mydb.commit ()
elif che=6: #Display Issued Books
print ("ID, NAME, SUBJECT, S_NAME, S_CLASS")
cur.execute("select from issued_books")
amcur.fetchall()
for i in a:
print (1)
mydb. commit()
elif ch==7:
break
else:
print ("Invalid input !")
else:
print("Wrong username/password I1")
elif cn2:
break
else:
print("Invalid input !!")