0% found this document useful (0 votes)
15 views6 pages

Adobe Scan Dec 16, 2024

Computer science project

Uploaded by

sukerdharune
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Adobe Scan Dec 16, 2024

Computer science project

Uploaded by

sukerdharune
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CONTENTS

S.No. TOPIC PAGE NO.


COVER PAGE

2 ACKNOWLEDGEMENT (ü)
3. MAIN CODE FOR LIBRARY MANAGEMENT SYSTEM

4 DATABASE AND TABLE DESCRIPTION

5 EXECUTING THE CODE

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

c=int (input ("Enter your choice : "))


if c=1: #Login
cont1=input ("Enter Username :")
cont2=input("Enter Password : ")
cur.execute("select from login")
for 1 in cur:
t_user,t_pas=i
if contl==t user and cont2==t pas:
print("Login Successful !!")
loop1='n'
while loopl=="n':
print ("mm

1. Add new books


2. Remove any book
3. Issue book to student
4. Return book
5. View available books
6. View issued books
7. Logout

ch=int (input("Enter your choice : "))


if ch=l: #Adding Books
loop2='y
while loop2=='y':
print ("Please enter the required data correctly !I")
b_id=int(input ("Enter book id : "))
b_name=input ("Enter book name : ")
sub=input ("Enter subject: ")
quant=int (input ("Enter quantity : "))
cur.execute("insert into available books
values(* "+str (b_id)+"*,*"+b_name+"",*"+sub+"*,*"+str(quant)+"*)")
mydb.commit ()
print("Data inserted successfully !!")
loop2=input("Do you want to add more books? Press (y/n)
as per your choice : ").lower()
loopl=input ("Do you want to logout? Press (y/n) as per your
choice : ").lower()

elif ch==2: #Removing Books


cur.execute("select id from available_books")
count=0
for i in cur:
idd=i
count=count+1
1f count=:
print ("There are no available books !!")
else:
b_ id=int (input ("Enter book id to remove the required
book : "))

cur.execute("select from available books")


flag=0
for i in cur:
t_id,t_name,t_sub,t_quant=i
if t_id==b id:
flag=1
if flag==l:
cur.execute("delete from available books where
id="+str (b_id)+"*")
mydb.commit ()
print("Data deleted successfully !")
else:
print ("Please enter correct id !!")

elif ch==3: #Issuing Books


b_id=int (input ("Enter book id : "))
flag-0
cur.execute("select from available books where
id='"+str(b_id)+"")
for i in cur:
t id, t name,t sub,t quant=i
flag=1

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 !!")

You might also like