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

computer science activity

Library management system

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)
3 views

computer science activity

Library management system

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/ 19

CONTENTS

Topic

Cover page

Acknowledgement
Main code for
Librarymanagement system

Database and table discription

Executing the code


Main Code for Library Management System
;! LIBRARY MANAGEMENT SYSTEM :
l•port •ysql.connector iS •sc
•ydb•■ sc.connect(host•'localhost•,user■ · root',passwd•'python')
cur■-ydb.cursor()
print ( .... '"

•• Welc011e to Library Manage"1ent Systea ••

j (reating Dat abase :


cur.execute("create database if not exists library_~ana1eaent_system'")
cur.execute('"use library_management_systa")
cur.execute('"create table if not exists available_books(id int primary key not
null,nMe varchar(25) not null,subject varchar(25) not null,quantity int not
null)'")
cur.execute('"create table if not exists issued_book.s(id int not null,book_naae
var-char(2.5) not null.,book_subject val"'char(2S) not null.,stu_naae var-char(2.9&)
priaary key not null.,stu_class varchar{25) no~ 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
nuU,password varchar(2S) primary key not null)")
aydb.coait()
flag■e

cur.execute("select • fr01t l01in")


for- 1 in cur: # if l ogin does n't have any va lue , loop will not execut e !!
flag• 1
if flag~e:
cur.execute("insert into login values(•Admin@123','1234')'")
11Ydb.commit()

#Loop-- >Main Workinn


while True:
print('"""
1.Login
2.Exit

c.::int(input( • Enter your choice : • »


if c---1: "Login
contleinput("Enter Username: ·>
cont2•input(·Enter Password : ·>
cur-.execute(·select • from lo11n·)
for 1 in cur:
t_user,t_pas•i
if cont1-t_user and cont2-t_pas:
print("Lo1in Successful ft'")
loop1•'n'
while loopl••in•:
print(·--

1. Add new books


2. Remove any book
3. Issue book to student
4, Return book
5. View available books
6. View .i ssued books
7. Losout

c.h•int(input("Enter your choice ''))


if ch-1: ~Adding Books
loop2-'y'
while loop2-'y':
print("Please enter the required data correctly 11 "')
b_ld•int(1nput(·Enter book id ·))
b_naffle•input(·enter book na~e : ·>
sub ■ input("Enter subject :
111
)

quant•int(input("Enter quantity : '"))


cur.execute(·tnsert into available_books
values(' "+str(b_id)+· ·, '·+b_name+'", • "+s.ub+" •, • "+str(quant)+• •)"')
mydb.cOfllllit()
print( "Data inserted successfully 11 '")
loop2=input(·0o you want to add -,re books? Press (y/n)
as per your choice : ·),lower(}
loopl•input("Oo you want to logout? Press (y/n) as per your
choice : ••). lower()

elif ch-2: "Removing Books


cur.execute( select id frOfll available_books")
0

count=0
fOf" 1 in -c ur:
idd•i
count•count+1.
1f count••0!
print( "The-r,e are no available books 11 "')
else:
b_id ■ int(input(·ERter book id to reaove the required
book '"))
cur.execute( .. select • from available_books")
fla1•e
for i in cur:
t_id.t_naae,t_sub.t_quant=i
if t_id=b_id:
flag•l
if flage=1:
cur.execute(·delete from available_book5 where
ld•'·+rtr(b_id)+ .. i")
inydb. co111d t ()
print( .. Oata deleted successfully 11")
else:
print("Please ent,e r correct id 11 ")

elif ch=3: ~Issuing Books


b_id=int(input("Enter book id : "))
flag-e
cur.execute( select • from available_books where
0

id•'·+str(b_id)+"'")
for i ln cur:
t_id,t_name,t_sub,t_quant•-i
flagal

if flag!•l:
print("Please enter the correct id as per the available
books I! ,.)
else:
1f t_quant>e:
s_name•input( '"En1:er student' n..e : ")
s_cl1ss•input("Enter student class: -)
s_doi•input( ·Enter date of issue : "')
s_dor-input(·enter date of ret.ul'"n : '")
cur.e:icecuteC-ins~rt into issued_books
values(' '"+str(b- id)+"'' # ' .. +t- name+• # '"+t- sub+'" ' • "+s- naae+"'' ' ''"+s- clas.s+'" ,. • .. +s
01

doi+ .. ' '"+s dor+"'')•)


- ' - quan=t_quant-1
cur.execute(-update available_books set
quantity•• 1'+str(quan)+·' lllh1re id•' " ♦ str(b_id )+" • ")
mydb.COMit()
print("Book issue(j successfully II")
else:
print("Books are issued already 11 Please wait
until they are returned or issue another book I I")
el1f chaa4: UReturning Books
b_id•int( input( "Enter id of the book to be returned : ·»
snaae:lnput("Ente-r naae of the student who issued the book

flag.&
t_id•8
t_na11~e
t_quant-e
c ■e
(1•9
cur.execute("select distinct id fr011 issued_boaks order by
ld'")
fDf" 1 in cur:
if int(1[6] )=b_id:
t_idaint(i[e])
flag+e1
if fla1==e:
p,.int( "No such boOk 1s issued 11 ·)
else:
cur.execute(•select stu_name fr,oa available_books
A,issued_books I where A.id•"'+rtr(t_id)+'" and A,id•I.id and
I. stu_nai.e•' '"+snaine+"' '"')
for i in cur:
t_name-=str(i.[0) )'
c-c+l
if cl •6:
cur.exec11te(·select quantity frOII available_boolcs
·where id•' .. +str(t_id)+•' •)
for j in cur:
t_quant ■ 1nt(j[0])

cl+•l
if clJ ■e:
qua nt=·t_quant-+l
cur.execute("update available_books set
quantity-''"+str(quant)+·· where id-'·+str(t_id)+"'")
cur.execute( ..delete fro. issued_book.s where
id•• "+str(t_id)+"' and stu_name• • •·+t_n,aae+ .. ' ")
mydb. coait()
print(·aook ~•turned successfully II")
else:
print("llo such student has issued this book II")
elif ch••S: WOisplay 8oocs
print("lO , NAME , SUBJECT , QUANTITY")
cur.eKecute( "select • from available_books")
a•cur.fetchall()
for 1 in a:
print(i)
lll)ldb. commit()
ell f Ch=6: #Display 15S Jed Books
print("ID, NAHE, SUBJECT, S_NAME, S_CLASS")
cur.eKecute("select • from issued_books")
a•cur.fetcholl()
for 1 in o:
print(i)
lll)ldb. commit ()
elif ch••7:
break
else:
print("Invalid input I I")
else:
print("Wrong username/password 11 ")
elif c•• 2:
break
else:
print("In11alid input 11" )
Database and Table Description
I 11 I I l·t .,: , r· ,, .1•;•·n1·nt

Database and the tables

-- • - - - ♦ -

F1elJ 1-\ey f • ll·a

PRI IW ~-
.. , 1~; IJll c._
•,i"1 tJI I'- .
t 11, ., "~ ! t , ! n t r,11 ..

ti I',-l,·1• 1r

Description of the table "available_books"

r' , ', I I • , t, ', ,~

~ 1,· l d

l ·1 l
.ioi-< 11.,rll' .. \ I , 11,11

:JI) I ◄ '.II! _I •. , ."II.,: I I. 1 I •

.,u·c11,11 Pi1 1
•. \l'C l1;1r
:J ,\ ':. ,_. a f l •- ' · •·

·,,.,: I

Description of the table "issued_books"


• ! 1 .,

l;',• !

Description of the table "login"


Executing the Code:
We l c oaa r..o L.Ui t a..'7 Ka..!i.atJ ll:.l:Wnt. fl y a t u:i

fl,t 111: you t c:l••J l <C t t


Ent•r Uai.rn•,.,. 1 iwi.ant1 2 J
11 l e t f 01a .n .. u 1tl I UJ4
IP, lft lll" -C<ti,, • f , 1 ,I

1 • A Jd r.1111 boob
1 , 11Jr11,ov<11 .,.y t:.cok
J. l a aue bOGt t o e t UIJ~n L
• , M r urn 1~-.;.ol;
!I . VJ. c-v ava Llab l ■ boob
Vic-v la:1i..S boa~
1. I.D9t:rt1 !.

Login

I• llli.ll he I ..I
• , r..a,.... •~ r....-.: ..
I, t,, _. I • ~ ,r~
• . P ~-=rn l:a;.gl
,,. 1• 1111 •vAt J al l• t".;io•.,
&c • ._ , .,. l .....-1 l •.:ob
-y . L, ,.

b •u f""4l c, I C-. 1 l
l"M•M • 1..• t t.h I r:i l r • t
l'M•r l ~ 1 1 I I
IIA!.•t t::tdll . . . . I Ml. Mil t
tllb r •wJ•~l • l"lly• I r 1
&M.•1 <f'UII' 11, I Jn
ea•• 1:..aat • e1 1 • ◄ .r ,,. ,.
~ -,=- • •" '' t e:11 l!nt • I &...1J t1 ■..11 a lt/td • • p•J 't l
,: . . . . . . .. . . •t t ... 1 ... , ltd . ,. _,, ...-. 1, "
IA~•• a-I IJ ' I
"-• •1 - ■- I All ... 'll
LM•• ••l-1
u , • ., .-ua tai.j •
I •- l • I O r
1:a
:..,. u,a- 11 .J • r 11, ,,
to 1 - ••n l t u • 1- •• ~ : lr/11 1 u I r ,.. " _ l.,_ • ,
Jl •• n ,..,. ,. _., tt
bl.!_u r-.ll l!J I J
I f t rfl Sa la ..:'1- 'J ~'
! . M , . a ; : ~ ~ , 0. . . 1
LJ.• •: ttllll.a I l'tUl>-ll O
t.a..:.a% -;..ur...:.t1 1 ' :~
:.· , LE.• •n .,., . ...-:"""l't• 11 t 1J t
:.v r-:u -.n.t t. u • ~ a:> t• tioo:b.! t . ...u lt lft t &>- l 'C t 'ro,.U dllC J. C. a 'f
,:-. . . . . , ... s- • t)• ,-....p .,.,..!I,.., .. =a' . M-1. J J ti
U~ . . l • 11 I 4
CALt 1 . . . . .... I CHIV
t&· •r ._)ff ' 1 a...,,.r..,,
&.atu .....,.u ,-, 1 to
"''• ,,._ ,,...,, • - I lit
i:.. ,.... ,. ""' ao 1• ,_u, ,•
:..

Adding New Books


I ~. 1

Table "available_books" after adding books

1. Add new boo k~


2. Remove any book
3 . l55Ue book to ~tuden t
4 . Return book.
5 . View available books
6. Vie w issued books
7. Logout

Encer your choice : 2


Enter bo ok id to remove the required book 2
Data deleted succes3fully ! !

Removing Books

;, ; ~ ,,I I !
. ·. ,1., l

Table "available_books" after removing book


En t er yo u ~ c h ~i c e : l
1. Add n e w h-oor.a £ n~or boo k id : l
2 . Romov~ any bo,,r.
J. ! :, :mo ~ k t o at u d c, nt
Ein tor otudont n o.m9 : Nn vdl'op
Ent.-..r .:, tudt;ri• Clll:•u:1 : l2
•I .Re- turn boo t.
En ~o r ~ntr o t i ~o uP : 2023 - 12- 17
~. Vi llw nw, t l 11b 1 .. b ook o
b, Vi ow i ~~ u~d bo~ k~ Entor d~ t u of rut ucn : 202) - 12· 24
eook l ~AUOd ~uc c e ~~ ful ly I I
l . l,09c ut

&nt~ r yow: chol~~ : 3


En t e r y ou ~ cho i ce : )
::nt e~ b,3ok i d : l
Ent e r be: ok 1.d : 3
tnt:e r .s tud e nt. nac..."' : A ►-~h a t
Ent~r ~tud~n~
ndm':! : An ~hUJlitl.n
:=nt'!> : ~ t ud o n t elG :,.., : 12 Ente r ~t ud~ :
clA~3 : ~2
~nt~ ~ dot~ of i ~~u~ 1 2023-12-2 0 Ent e r dot ~ o f
i~~ue : 2023-12 - 20
Ent<1 c: ;Jal: a o! ::C!-!. L1 rn : 2023 - l. 2 - 21 Enter dnt~ of
re tu~n: 2023 - 12- 27
Boot 1:rnu od c:uc c;e :,:s f u.11.y 11 Book ii,~uod !3UCC~ :Sil !ully I t

lssu ing Books

I h,1• 1 '.

,. , · t

Table "available_books" after issuing books

1. Add now book:,


2. R QJIIO VO irny book
l . ! ~~un boo k ~o ~tud~n~
~ . 'R<•t Ul n b o o k
5 . Vi o w n vn ll ab l u ~ ~k ~
i . Vi e w i ~~ u od b~ ►..!J
7 . Loqci uc.

~nt ~ r yo ur cho i c~ : 4
Ente r i d o ~ t h~ book t o t ~ r ~ t u.rned : l
En t er ~ e of t:he .st u d<:nt: vho i :13u e d t:he booi: . Nav deep
Bo-o k rt> t: Urn!E" cl a uccP~.!! Eull :,· ! !

Returning Book
• '. •. ,- t

Ir- I•

•• ; ~ •I 'l I I !

~. ,_. t_

Table "available books" and Table "issued books" after


returning book

l. Add new books


2. Remove any b oo k
3. I ssue boo k t o student
4. Re tu rn boo k
5. View a v ailable boo ks
6. View issued boo ks
7. Log out

Enter your choice : 5


ID , NAME , SUBJECT , QUANTITY
(1, ' Ar i han t ' , 'Phys ic s ' , 2 0)
( 3, ' Oswal', ' Mathema ti c~ •, 24 )
(4 , 'GRV ', 'Geography ', 1 0)
I

Displaying Available Books


I • A•l l n••hoo\:.lt
:. Sl • <M> V• ,riv l>oolt
.1 . fQu i,• t-<>ot. • o r.tu • c t
1. lle t u , r, boot
, , 'II w 1-v,- I l•hl,o La
.. . ',' t., V I J!l!Ult(I l!O:ltri
, . L<' J:>lll

tr.le e you. h 0 1 ~ 1 i
: 0 . KM£ , OUII J!XT • I! IIAlC , ol CLA.:i•
o. ' Gs • ;JJI', 'M.ac.h■- 1:.1 0', 'Ar .. '.hcaan' , •t:" . z,, .
d&V"~- . da t • ll O:n. 12 . d•~ c:t - . i.1.A t ■ C2t- ? 3 , .. 21,i

Displaying Issued Books

! . Add new books


2 . Remove any book
3. Issue book to student
4. Return boo k
5. View available books
6. View i s sued books
7 . Logout

Enter your c hoice : 7

I . Login
2 . E:-:it

Enter your choice : 2


>>>
Exiting the pr,ogra m
Errors
1 . Add new books
2. Remove any book
3. Issue book t o student
4 . Return book
5. View a v a i lable books
6 . View issued boo ks
7 . Logout

Enter your choice : 8


rnvalid i nput !!
1
Inva Iid Choice

*"" We lcome t o Library Management Sy:, t em **

l. Login
2.Exit

Enter your c hoic e : 1


Enter u~ername : Navdeep
Ente r Password : 12
Wrong username / pa.ssword ! !

l.Login
2. Ex.it

Ente r your choice:

Invalid Credentials
1. Add new booktJ
2 . Removo eny book
3 . I~sue book to 5tud~nt
'l . Return book
5 . View available books
6 . View issued books
7. Logout
- - -- - -- ---- - - --- - ---
Enter your choice : 3
Enter book id : 34
Plea~e enter the correct id as per the ovc iloble book~ !!

1. Add new books


2 . Remove any b ook
3. Issue book to student
4 . Return book
5 . View available books
6 . View issu ed books
7 . Logou t

En ter your choi ce : 2


Enter book id to remove the requi r ed book : 76
elease enter c orrect id!!
1
Wrong book id entered while Issuing or Removing book

1. Add new books


2 . Re-tnov·e ony book
3 . I 3sue book to 3 tudent
4 . Recur n book
5 . View avai l abl e books
6 . Vi~w i3SUed book~
7. Logout

Enter your choic e : 4


En t~r id of the book to b e re tu rned : 34
En ter name of the student who is~ued the book Ak~ha t
No ~uch boo k ia issued ! f

Wrong input while returning book


BIBLIOGRAPHY:
• Computer Science with python - Sumita Arora
• www.mysgl.com
• www.python.org

You might also like