no classification
no tag
no datas
posted on 2023-06-06 09:53 read(124) comment(0) like(26) collect(2)
Libraries, as a gathering place and display platform for documents, often play a role in leading the advancement of culture, and are an indispensable infrastructure for every university, and the library management system is the key to the normal operation of a library. This course design uses Python language to make programs to realize functions such as adding book information, modifying book information, querying book information, deleting book information, user login, user registration, book borrowing status query, and exporting book information. The program involves list, dictionary, file stream operations and object-oriented thinking, including book object definition, user object definition, file read and write and list storage book object.
class Book:
def __init__(self, name, author, status, index):
self.name = name
self.author = author
self.status = status
self.index = index
def __str__(self):
return f'{self.name},{self.author},{self.status},{self.index}'
class People:
def __init__(self, name, password):
self.name = name
self.password = password
def __str__(self):
return f'{self.name},{self.password},{self.mode}'
class PeopleManage:
def __init__(self):
self.people_list = []
def menu(self):
print("请选择如下功能------------")
print("1:登陆")
print("2:注册")
number = int(input("输入序号:"))
if number == 1:
self.login()
elif number == 2:
self.register()
else:
print("输入错误,请重新输入!")
print("\n")
self.menu()
def login(self):
print('用户登陆')
name = input('账号:')
password = input('密码:')
if not self.people_list:
print("恭喜你成为本系统第一个用户")
print("\n")
self.register()
else:
for i in self.people_list:
if name == i.name and password == i.password:
print('登陆成功!')
print("\n")
book = BookManagers()
if i.name == '110':##默认管理员账号为110
print("欢迎管理员登陆!")
book.run(1)
else:
print("欢迎用户登陆!")
book.run(0)
elif name == i.name or password == i.password:
print("用户名或密码输入错误")
print("\n")
self.login()
else:
print('该用户未注册!')
print("\n")
self.register()
def register(self):
print('用户注册')
name = input('账号:')
password = input('密码:')
peoples = People(name, password)
self.people_list.append(peoples)
print('注册成功!')
print("\n")
self.login()
class BookManagers:
def __init__(self):
self.book_list = [] # 建立一个存储数据用的列表
self.apply = [] # 图书建购表
def run(self, number): # 程序入口函数
if number == 1:
while True:
self.show_menu() # 显示功能菜单
menun_num = int(input("请输入您需要的功能序号:")) # 用户输入功能序号
# 根据输入的序号,执行不同的功能
if menun_num == 1: # 添加图书
self.add_book()
self.save_book()
elif menun_num == 2: # 查询图书信息
self.search_book()
elif menun_num == 3: # 显示所有图书信息
self.show_book()
elif menun_num == 4: # 保存图书信息
self.save_book()
elif menun_num == 5: # 删除图书信息
self.del_book()
self.save_book()
elif menun_num == 6: # 修改图书信息
self.modify_book()
self.save_book()
elif menun_num == 7: # 统计借出
self.data_statistic()
elif menun_num == 8:
self.show_apply()
elif menun_num == 9: # 退出登陆
peoples = PeopleManage()
peoples.menu()
else:
while True:
self.show_menu1()
menun_num = int(input("请输入您需要的功能序号:")) # 用户输入功能序号
# 根据输入的序号,执行不同的功能
if menun_num == 1: # 查询图书信息
self.search_book()
elif menun_num == 2: # 显示所有图书信息
self.show_book()
elif menun_num == 3:
self.buy_book() # 图书建购
elif menun_num == 4: # 退出系统
peoples = PeopleManage()
peoples.menu()
# 定义功能函数
def show_menu(self): # 显示功能菜单
print("请选择如下功能------------")
print("1:添加书籍")
print("2:查询书籍信息")
print("3:显示所有书籍")
print("4:导出书籍信息")
print("5:信息删除书籍")
print("6:修改书籍信息")
print("7:统计借出")
print("8:展示建议")
print("9:退出登陆")
def show_menu1(self): # 显示功能菜单
print("请选择如下功能------------")
print("1:查询书籍信息")
print("2:显示所有书籍")
print("3:图书建购")
print("4:退出登陆")
def add_book(self): # 添加图书
# 用户输⼊图书名称、作者、状态、编码
name = input("请输入书籍名称:")
author = input("请输入书籍作者:")
status = input("请输入书籍状态:")
index = input("请输入书籍编码:")
book = Book(name, author, status, index) # 创建图书对象
self.book_list.append(book) # 将该图书对象添加到列表
print(self.book_list) # 打印信息
print(book) # 打印信息
def del_book(self): # 删除图书
del_name = input('请输⼊要删除的书籍名称:') # 用户输入目标图书名
# 如果用户输入的目标存在则删除,否则提示目标不存在
for i in self.book_list: # 遍历图书信息列表
if i.name == del_name: # 查找图书是否存在
self.book_list.remove(i) # 删除图书信息
print("成功删除该图书信息!")
print("\n")
break
else:
print("查无此书!")
print("\n")
print(self.book_list) # 打印图书列表,验证删除功能
def modify_book(self): # 修改图书信息
modify_name = input('请输⼊要修改的书籍名称:') # 用户输入目标名称
# 如果用户输入的目标存在,则修改信息,否则提示图书不存在
for i in self.book_list: # 遍历图书信息列表
if i.name == modify_name: # 查找图书是否存在
# 更改学员信息
i.name = input('请输⼊书籍名称:')
i.author = input('请输⼊书籍作者:')
i.status = input('请输⼊书籍状态:')
i.index = input('请输入书籍编码:')
print("成功修改该图书信息!")
print(
f'书籍:{i.name}, 作者:{i.author}, 状态:{i.status}, 编码:{i.index}') # 打印图书信息,验证是否更改成功
print("\n")
break
else:
print('查无此书!')
print("\n")
def search_book(self): # 查询图书信息
search_name = input('请输⼊要查询的书籍名称:') # 用户输入目标图书名
# 如果用户输入的目标存在,则打印目标信息,否则提示目标不存在
for i in self.book_list: # 遍历目标信息列表
if i.name == search_name: # 查找目标图书是否存在
print(
f'书籍名:{i.name}, 作者:{i.author}, 状态:{i.status}, 编码:{i.index}')
print("\n")
break
else:
print('查无此书!')
print("\n")
def show_book(self): # 显示所有图书信息
print('姓名\t作者\t\t状态\t编码') # 打印信息名称
for i in self.book_list: # 遍历信息列表
print(f'{i.name}\t{i.author}\t\t{i.status}\t\t{i.index}') # 打印图书信息
print("\n")
def save_book(self): # 导出图书信息
f = open('book.txt', 'w', encoding='utf-8') # 打开文件
new_list = [i.__dict__ for i in self.book_list] # 将图书数据转换成列表字典数据
print(new_list) # 打印信息
f.write(str(new_list)) # 转换成字符串,存入文档
f.close() # 关闭文件
def data_statistic(self): # 统计图书借出状态
yes = no = 0
for i in self.book_list:
if i.status == '借出':
yes += 1
else:
no += 1
print("已借出图书{}册:".format(yes))
for i in self.book_list:
if i.status == '借出':
print(f'书籍名:{i.name}, 作者:{i.author}, 状态:{i.status}, 编码:{i.index}')
print("\n")
print("未借出图书{}册:".format(no))
for i in self.book_list:
if i.status == '未借出':
print(f'书籍名:{i.name}, 作者:{i.author}, 状态:{i.status}, 编码:{i.index}')
print("\n")
def buy_book(self): # 读者建购图书
name = input("请输入书籍名称:")
author = input("请输入书籍作者:")
reason = input("建购原因:")
self.apply.append(['图书名称:{},作者:{},建购原因:{}'.format(name, author, reason)])
f = open('apply.txt', 'w', encoding='utf-8') # 打开文件
f.write(str(self.apply)) # 转换成字符串,存入文档
f.close() # 关闭文件
def show_apply(self): # 展示读者建购表
f = open('apply.txt', 'r', encoding='utf-8') # 打开文件
data=f.read()
print(data)
print("\n")
f.close() # 关闭文件
if __name__=='__main__':
people = PeopleManage()
people.menu()
Author:Soledad
link:http://www.pythonblackhole.com/blog/article/79664/9b1061fa519ca78bbbd1/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!