In this article, we share examples of python code to achieve the specific code of the library management system for your reference, the details are as follows
library management system
Function Introduction
- When adding a book, the book ID cannot be duplicated and the book name can be duplicated.
- Delete, query, modify function, enter the name of the book to provide all the books with the same name, the user can be in accordance with the book serial number of a specific book operation
- Display books, in rows, with information about one book per row
Book information is saved in txt text file format in the following format
source code (computing)
#-*- coding=utf8 -*- # @author:sololi # date: 2020/11/12 # Document description: data import sys def print_muen(): print("---- menu tips ----") print("[1]:Add book") print("[2]:Search for books") print("[3]: Deletion of books") print("[4]:Modify book information") print("[5]:Show all books") print("[6]:Exit") def add_book(): book_id=input("Please enter the book number.") book_name=input("Please enter the name of the book.") book_loc=input("Please enter the location of the book.") for i in books: if book_id==i["book_id"]: print("Duplicate numbering") break else: book={} book["book_id"]=book_id book["book_name"]=book_name book["book_loc"]=book_loc (book) new_file(books) print("Added successfully.") def find_book(): jg=0 while True: book_name=input("Enter the title of the book you're looking for.") for i in books: if book_name==i["book_name"]: print(i) jg=1 if jg==0: print("Search failed. Please re-enter.") continue elif jg==1: break def dell_book(): book_name =input("Please enter the title of the book.") i=0 j=0 jg=0 flag=[] while i<len(books): if books[i]["book_name"]==book_name: id=books[i]["book_id"] (id) print("Book Number:{}".format(id)) jg=1 i+=1 if jg==0: print("Can't find the title of the book.") if jg==1: book_id=input("Please enter the number of the deleted book.") i=0 while j < len(flag): if flag[j] == book_id: while i < len(books): if books[i]["book_id"] == book_id: del books[i] new_file(books) print("Deleted successfully.") break i+=1 break j+=1 else: print("Incorrect number entered.") return books def modify_book(): book_name = input("Please enter the name of the book to be modified.") i = 0 jg = 0 flag = [] while i < len(books): if books[i]["book_name"] == book_name: id = books[i]["book_id"] (id) print("本书Book Number:{}".format(id)) jg = 1 i += 1 if jg == 0: print("Can't find the title of the book.") elif jg == 1: book_id = input("Please enter the book number to be changed, or any other book number that needs to be changed.") for i in books: if book_id == i["book_id"]: New_id = input("New Book Number") if New_id == i["book_id"]: print("Input number duplicated") break else: New_name = input("New book titles") New_loc = input("New Book Locations") i["book_id"] = New_id i["book_name"] = New_name i["book_loc"] = New_loc new_file(books) break else: print("Input error.") def all_book(): for i in books: print(i) def read_book(data):# Read book information from a text file into books f = open(data, mode="r", encoding="utf8") books = () () for i in range(0, len(books)): books[i] = eval(books[i].replace("\n", "")) return books def new_file(books):#Update the contents of books to a text file i=0 nf = open('data', 'w+',encoding='utf8') # Open the file for writing by emptying the contents of the original text file while i<len(books): new=str(books[i]) (new) if i !=len(books)-1: ("\n") i+=1 () if __name__=="__main__":# Main processes while True: data="data" books=read_book(data) print_muen() choice=input("Please enter your selection.") if choice=='1': add_book() all_book() elif choice=='2': find_book() elif choice=='3': dell_book() all_book() elif choice=='4': modify_book() all_book() elif choice == '5': all_book() elif choice == '6': print("Thank you for your use.") (0) else: print("There's been an error in your entry. Please re-enter.")
A login and registration system can also be added:Click here
This is the whole content of this article.