0% found this document useful (0 votes)
67 views3 pages

LMS Proj123

This Python code defines functions for a library management system including adding books, issuing books to students, returning books, removing books, and displaying book and issued book information. The code connects to a MySQL database, takes user input, executes SQL queries/updates, and calls various functions to manage the tasks of the library system through a menu-based interface.

Uploaded by

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

LMS Proj123

This Python code defines functions for a library management system including adding books, issuing books to students, returning books, removing books, and displaying book and issued book information. The code connects to a MySQL database, takes user input, executes SQL queries/updates, and calls various functions to manage the tasks of the library system through a menu-based interface.

Uploaded by

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

import mysql.

connector as a
con=a.connect(host="localhost",user="root",passwd="????????????",database="????????
???????")

def addbook():
bn = input("Enter BOOK Name : ")
c = input("Enter BOOK Code : ")
t = input("Total Books : ")
s = input("Enter Subject : ")
data = (bn,c,t,s)
sql = 'insert into books values(%s,%s,%s,%s)'
c = con.cursor()
c.execute(sql,data)
con.commit()

print(">---------------------------------------------------------------------------
-------------<")
print("Data Entered Successfully")
main()

def issueb():
n = input("Enter Name : ")
r = input("Enter Reg No : ")
co = input("Enter Book Code : ")
d = input("Enter Date : ")
a = "insert into issue values(%s,%s,%s,%s)"
data = (n,r,co,d)
c = con.cursor()
c.execute(a,data)
con.commit()

print(">---------------------------------------------------------------------------
-----------------<")
print("Book issued to : ",n)
bookup(co,-1)

def submitb():
n = input("Enter Name : ")
r = input("Enter Reg No : ")
co = input("Enter Book Code : ")
d = input("Enter Date : ")
a = "insert into submit values(%s,%s,%s,%s)"
data = (n,r,co,d)
c = con.cursor()
c.execute(a,data)
con.commit()

print(">---------------------------------------------------------------------------
-----------------<")
print("Book Submitted from : ",n)
bookup(co,1)

def bookup(co,u):
a = "select TOTAL from books where BCODE = %s"
data = (co,)
c = con.cursor()
c.execute(a,data) # (10,)
myresult = c.fetchone()
t = myresult[0] + u
sql = "update books set TOTAL = %s where BCODE = %s"
d = (t,co)
c.execute(sql,d)
con.commit()
main()

def rbook():
ac = input("Enter Book Code : ")
a = "delete from books where BCODE = %s"
data = (ac,)
c = con.cursor()
c.execute(a,data)
con.commit()
main()

def dispbook():
a = "select * from books"
c = con.cursor()
c.execute(a)
myresult = c.fetchall() # [(1,2,3,4),(1,2,3,4)]
for i in myresult:
print("Book Name : ",i[0])
print("Book Code : ",i[1])
print("Total : ",i[2])
print("Subject : ",i[3])
print(">--------------------------------<")
main()

def ibooks():
a = "select * from issue"
c = con.cursor()
c.execute(a)
myresult = c.fetchall() # [(1,2,3,4),(1,2,3,4)]
for i in myresult:
print("Student Name : ",i[0])
print("Reg No : ",i[1])
print("Book Code : ",i[2])
print("Issue Date : ",i[3])
print(">--------------------------------<")
main()

def main():
print("""
LIBRARY MANAGER

1. ADD 2. ISSUE 3. SUBMIT 4. REMOVE 5. DISPLAY


""")
choice = input("Enter Task No : ")

print(">---------------------------------------------------------------------------
-----------------<")
if (choice == '1'):
addbook()
elif (choice=='2'):
issueb()
elif (choice=='3'):
submitb()
elif (choice=='4'):
rbook()
elif (choice=='5'):
print("1. All 2. Issued")
ch = input("Enter Task No. ")

print(">---------------------------------------------------------------------------
-----------------<")
if ch == '1':
dispbook()
elif ch=='2':
ibooks()
else:
print(" Wrong choice..........")
main()

def pswd():
ps = input("Enter Password : ")
if ps == "py143":
main()
else:
print("Wrong Password")
pswd()
pswd()

You might also like