project file on Library Management System
project file on Library Management System
Project File
On
Library Management System
Prepared By:
Name:
Class:
Session: 2024 – 2025
Board Roll No.
Saraswati Vidya Mandir
GT Road
Etah
Acknowledgement
It would be my utmost pleasure to express my sincere thanks to my computer
science teacher Mr. Yogesh Kumar Mishra is providing a helping hand in this
project. His unflagging patience, creativity and immense knowledge that he
shared with me have proved highly beneficial to me and have made my project
file both possible and successful.
Name:
Class:
Certificate
This is to certify that this project file has been completed by
_ bearing roll number
of class 12th during the session 2024-2025.
We certify that this project work is completely original and having unique
identify.
We congratulate him for his hard work and determination in carrying out
this practical work and wish him all the success in future.
def set_data():
bno = int(input('Enter Book number: '))
title = input('Enter title of Book: ')
subject = input('Enter subject of Book: ')
author = input('Enter Author of Book: ')
publication = input('Enter publication of Book: ')
dop = input('Enter date of purchase of Book: ')
price = int(input('Enter price of book: '))
print()
#create a dictionary
library = {}
library['bno'] = bno
library['title'] = title
library['subject'] = subject
library['author'] = author
library['publication'] = publication
library['dop'] = dop
library['price'] = price
return library
def display_data(library):
print('--------------------------------------------------')
print('Library DETAILS..')
print('--------------------------------------------------')
print('Book Number:\t\t', library['bno'])
print('Book Title:\t\t', library['title'])
print('Subject:\t\t', library['subject'])
print('Author:\t\t\t', library['author'])
print('Publication:\t\t', library['publication'])
print('Date of Purchase:\t', library['dop'])
print('Price:\t\t\t', library['price'])
def write_record():
#open file in binary mode for writing.
outfile = open('library.dat', 'ab')
while(True):
#serialize the record and writing to file
pickle.dump(set_data(), outfile)
ans = input('Wants to enter more record (y/n)?: ')
if ans in 'nN':
break
#close the file
outfile.close()
def read_records():
#open file in binary mode for reading
try:
infile = open('library.dat', 'rb')
except FileNotFoundError:
print('No record found..')
return
#read to the end of file.
while True:
try:
#reading the oject from file
library = pickle.load(infile)
#display the record
display_data(library)
except EOFError:
break
#close the file
infile.close()
def search_record():
#open file in binary mode for reading
try:
infile = open('library.dat', 'rb')
except FileNotFoundError:
print('No record..')
return
found = False
bno = int(input('Enter the book number you want to search: '))
#read to the end of file.
while True:
try:
#reading the oject from file
library = pickle.load(infile)
if library['bno'] == bno:
#display the record
display_data(library)
found = True
break
except EOFError:
break
if found==False:
print('Record not found!!')
#close the file
infile.close()
def delete_record():
print('\nDELETE RECORD')
try:
infile = open('library.dat', 'rb')
except FileNotFoundError:
print('No record found to delete..')
return
outfile = open("temp.dat","wb")
found = False
bno = int(input('Enter Book number: '))
while True:
try:
#reading the oject from file
library = pickle.load(infile)
#display record if found and set flag
if library['bno'] == bno:
display_data(library)
found = True
break
else:
pickle.dump(library,outfile)
except EOFError:
break
if found == False:
print('Record not Found')
print()
else:
print("record found and deleted")
infile.close()
outfile.close()
os.remove("library.dat")
os.rename("temp.dat","library.dat")
def modify_record():
print('\nMODIFY RECORD')
try:
infile = open('library.dat', 'rb')
except FileNotFoundError:
print('No record found to modify..')
return
found = False
outfile = open("temp.dat","wb")
bno = int(input('Enter book number: '))
while True:
try:
#reading the oject from file
library = pickle.load(infile)
#display record if found and set flag
if library['bno'] == bno:
print('title:',library['title'])
ans=input('Wants to edit(y/n)? ')
if ans in 'yY':
library['title'] = input("Enter the title ")
print('subject:',library['subject'])
ans=input('Wants to edit(y/n)? ')
if ans in 'yY':
library['subject'] = input("Enter new subject: ")
print('author name:',library['author'])
ans=input('Wants to edit(y/n)? ')
if ans in 'yY':
library['author'] = input("Enter new author name: ")
print('publication name:',library['publication'])
ans=input('Wants to edit(y/n)? ')
if ans in 'yY':
library['publication'] = input("Enter new publication name: ")
print('Date of purchase:',library['dop'])
ans=input('Wants to edit(y/n)? ')
if ans in 'yY':
library['dop'] = input("Enter new purchasing date: ")
print('Price:',library['price'])
ans=input('Wants to edit(y/n)? ')
if ans in 'yY':
library['price'] = int(input("Enter new price: "))
pickle.dump(library,outfile)
found = True
break
else:
pickle.dump(library,outfile)
except EOFError:
break
if found == False:
print('Record not Found')
else:
print('Record updated')
display_data(library)
infile.close()
outfile.close()
os.remove("library.dat")
os.rename("temp.dat","library.dat")
def intro():
print("=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x")
print("PROJECT ON LIBRARY MANAGEMENT SYSTEM")
print("\tBOOK MANAGEMENT")
print("SCHOOL : SARASWATI VIDYA MANDIR, ETAH")
print("=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x")
print()
time.sleep(1)
def main_menu():
print("MAIN MENU")
print("1. VIEW BOOKS")
print("2. ADMIN MENU")
print("3. EXIT")
def admin_menu():
print("ADMIN MENU")
print("1. ADD BOOK DETAILS")
print("2. DISPLAY ALL BOOK DETAILS")
print("3. SEARCH BOOKS ")
print("4. MODIFY BOOK RECORD ")
print("5. DELETE BOOK ")
print("6. BACK TO MAIN MENU")
def main():
intro()
while(True):
main_menu()
choice = input('Enter choice(1-3): ')
print()
if choice == '1':
read_records()
print()
elif choice == '2':
admin_menu()
echoice = input('Enter choice(1-6): ')
if echoice == '1':
write_record()
elif echoice == '2':
read_records()
elif echoice == '3':
search_record()
elif echoice == '4':
modify_record()
elif echoice == '5':
delete_record()
elif echoice == '6':
pass
else:
print('Invalid input !!!')
print()
elif choice == '3':
break
else:
print('Invalid input!!!')
print()
#call the main function.
main()
OUTPUT
Main Page
View Books
Admin Menu
Add Book Details
Display All Book Details
Search Books
Modify Book Records
Delete Book
Back to Main Menu
Exit