0% found this document useful (0 votes)
42 views4 pages

Python Project Code

This Python code defines functions for a library management system that allows users to add, search for, and check out books from a database. It connects to a MySQL database called "library_app" and defines functions to add members and books, issue and return books, and generate reports. The main menu allows selecting these options and calls the corresponding functions.
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)
42 views4 pages

Python Project Code

This Python code defines functions for a library management system that allows users to add, search for, and check out books from a database. It connects to a MySQL database called "library_app" and defines functions to add members and books, issue and return books, and generate reports. The main menu allows selecting these options and calls the corresponding functions.
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/ 4

PYTHON PROJECT CODE

-------------------
import mysql.connector as a
con=a.connect(host='localhost',user='root',passwd='marvel',database='library_app')

def addmember():
f=open('memberlist.csv','a',newline="")
d=csv.writer(f)

name=input('enter your name')


phone=int(input('Enter your phone number'))
rec=[name,phone]
d.writerow(rec)
f.flush()

print('member registration successfull')

ch=input('do you want to go to registration menu y/n')


if ch.lower()=='y':
main_1()

def searchmember():
f=open('memberlist.csv')
d=csv.reader(f)
phone=int(input('Enter your registered phone number\n'))
for i in d:
if int(i[1])==phone:
print('Welcome',i[0])
main()
else:
print('phone number not found.please sign in again')
main_1()

def main_1():
print("""1. Sign in
2. Sign up""")
print('\n')
choice=input("Enter Task No:")
if(choice=='1'):
print('\n')
addmember()
elif(choice=='2'):
print('\n')
searchmember()

def readmember():
f=open('memberlist.csv')
d=csv.reader(f)
for i in d:
print(i)

def searchmember():
f=open('memberlist.csv')
d=csv.reader(f)
phone=int(input('Enter your registered phone number\n'))
for i in d:
if int(i[1])==phone:
print('Welcome',i[0])
main()
else:
print('phone number not found.please sign in again')
main_1()

def addbook():
bn=input('Enter Book Name:')
ba=input("Enter Author's name:")
c=int(input("Enter Book Code:"))
t=int(input("Total Books:"))
s=input("Enter Subject:")
data=(bn,ba,c,t,s)
sql='insert into books values(%s,%s,%s,%s,%s);'
c=con.cursor()
c.execute(sql,data)
con.commit()
print("\n\n\n\nBook Added Successfully..........\n\n\n\n")
wait=input('\n\n\nPress enter to continue.....\n')
main()

def issueb():
n=input("Enter Student Name:")
r=int(input("Enter Reg no.:"))
co=int(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("\n\n\n\nBook issued successfully to:",n)
wait=input('\n\n\nPress enter to continue.....\n\n\n\n\n\n')
bookup(co,-1)
main()

def returnb():
n=input("Enter Student Name:")
r=int(input("Enter Reg No.:"))
co=int(input("Enter Book Code:"))
d=input("Enter Date:")
a="insert into return1 values(%s,%s,%s,%s);"
data=(n,r,co,d)
c=con.cursor()
c.execute(a,data)
con.commit()
print("Book returned by:",n)
wait=input('\n\n\nPress enter to continue.....\n\n\n\n\n\n')
bookup(co,1)
main()

def bookup(co,u):
a="select total from books where bcode=%s;"
data=(co,)
c=con.cursor()
c.execute(a,data)
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()
wait=input('\n\n\nPress enter to continue.....\n\n\n\n\n\n')
main()

def dbook():
ac=int(input("Enter Book Code:"))
a="delete from books where bcode=%s;"
data=(ac,)
c=con.cursor()
c.execute(a,data)
con.commit()
print("Book deleted successfully")
wait=input('\n\n\nPress enter to continue.....\n\n\n\n\n\n\n\n\n\n\n\n')
main()

def dispbook():
a="select*from books;"
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print("Book name:",i[0])
print("Author:",i[1])
print("Book code:",i[2])
print("Total:",i[3])
print("Subject:",i[4])
print('\n\n')
wait=input('\n\n\nPress enter to continue.....\n\n\n\n\n\n\n\n\n\n\n\n')
main()

def report_issued_books():
a="select*from issue;"
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print(i)
wait=input('\n\n\nPress enter to continue.....\n\n\n\n\n\n\n\n')
main()

def report_return_books():
a="select*from return;"
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print(i)
wait=input('\n\n\nPress enter to continue.....\n\n\n\n\n\n\n\n\n\n\n\n')
main()

def main():
print("""L I B R A R Y M A N A G E M E N T A P P L I C A T I O N
___________________________________________________________
1. ADD BOOK
2. ISSUE OF BOOK
3. RETURN OF BOOK
4. DELETE BOOK
5. DISPLAY BOOK
6. REPORT MENU
7. EXIT PROGRAMM""")
print('\n')
choice=input("Enter Task No:.......")
if(choice=='1'):
print('\n')
addbook()
elif(choice=='2'):
print('\n')
issueb()
elif(choice=='3'):
print('\n')
returnb()
elif(choice=='4'):
print('\n')
dbook()
elif(choice=='5'):
pint('\n')
dispbook()
elif(choice=='6'):
print('\n')
print('''REPORTMENU
1. ISSUED BOOKS
2. RETURNED BOOKS
3. GO BACK TO MAIN MENU\n\n\n''')
choice=input("Enter Task No:.....")
print('\n\n\n\n\n\n\n')
if choice=='1':
report_issued_books()
elif choice=='2':
report_return_books()
elif choice=='3':
main()
else:
print("Please try again....,nnnnnnnnnnn")
main()
elif(choice=='7'):
print('\n\n\n\n\n\n\nThank you and have a great day ahead.......\n\n\n\n\n\
n\n\n\n\n\n\n')
else:
print('Please try again.........\n\n\n\n\n\n\n\n\n\n')
main()
main()

You might also like