books=[ {"bookname":"红楼梦","numbers":2}, {"bookname":"西游记","numbers":3}, {"bookname":"三国演义","numbers":2}, {"bookname":"水浒传","numbers":2}, {"bookname":"龙王传说","numbers":2}, {"bookname":"绝世唐门","numbers":3} ] students=[ {"id":"101","password":"123","name":"张三","books":["红楼梦","龙王传说"]}, {"id":"102","password":"123","name":"李四","books":["红楼梦","三国演义"]}, {"id":"103","password":"123","name":"王五","books":["水浒传","西游记"]}, {"id":"104","password":"123","name":"赵六","books":["红楼梦","水浒传"]}, {"id":"105","password":"123","name":"小明","books":["三国演义","龙王传说"]}, ] def id_book(id): for dict_stu in students: if dict_stu["id"]==id: return dict_stu["books"] def lend_book(book): stu_books=id_book(user_name) if len(stu_books)==5: print("只能借5本") return for dict_book in books: if book == dict_book["bookname"]: if book in stu_books: print("您已借过这本书") print(id_book(user_name)) else: if dict_book["numbers"]==0: print("这本书已借光") print(dict_book) return for dict_stu in students: if dict_stu["id"]==user_name: dict_stu["books"].append(book) print(id_book(user_name)) dict_book["numbers"]-=1 print(dict_book) break else: print("没有这本书") def repay_book(book): stu_books=id_book(user_name) if book in stu_books: stu_books.remove(book) for dict_book in books: if book == dict_book["bookname"]: dict_book["numbers"]+=1 print(dict_book) print(id_book(user_name)) else: print("您没有这本书") print(id_book(user_name)) def change_password(): old_passwd=input("请输入原密码") new_passwd=input("请输入新密码") new_passwd1=input("请再次输入新密码") if old_passwd!=get_password(user_name): print("原密码错误") return elif new_passwd1!=new_passwd: print("两次新密码输入不一致") return elif len(new_passwd)<6: print("请输入长度大于6的新密码") return else: for dict_stu in students: if dict_stu["id"]==user_name: dict_stu["password"]=new_passwd print("修改成功") def success_login(): while True: choice=input("1.借书 2.还书 3. 修改密码 4.退出") if choice=="1": book=input("请输入您要借的书名") lend_book(book) elif choice=="2": book=input("请输入你要还的书") repay_book(book) elif choice=="3": change_password() elif choice=="4": print("退出个人图书管理系统成功") print("已进入登录界面") login() break def get_password(id): for dict_stu in students: if dict_stu["id"]==id: return dict_stu["password"] def login(): global n,user_name,pass_word user_name=input("请输入您的id") pass_word=input("请输入你的密码") if n>2: print("您的账号已锁定") return if user_name=="退出": return if pass_word==get_password(user_name): print("登录成功") success_login() else: print("登录失败请重新登录") n+=1 login() n=0 user_name="" pass_word="" login()