book=[{'书名':'红楼梦','作者':'曹雪芹','数量':3},{'书名':'从百草园到三味书屋','作者':'鲁迅','数量':3},{'书名':'从百草园到三味书屋','作者':'周树人','数量':3},{'书名':'水浒传','作者':'施耐庵','数量':3},{'书名':'西游记','作者':'吴承恩','数量':3}]
id_password=[{'用户名':'管理员','密码':'123456'},{'用户名':'用户','密码':'123456'}]
state=True
state_administrator=True
state_user=True
borrowing_book=[]
def log_in(id,password):
i=0
j=0
for temporally in id_password:
j+=1
if id==temporally['用户名'] and password==temporally['密码']:
i+=1
break
if i>0:
return j
else:
return 0
def Modify_the_user():
id=input('请输入你要修改的账户的用户名:')
password=input('请输入你要修改的账户的密码:')
j=log_in(id,password)
if j>0:
i=0
for temporally in id_password:
if id==temporally['用户名'] and password==temporally['密码']:
id_password.remove(temporally)
id=input('请输入新的用户名:')
Password=int(input('请输入新的密码:'))
temporally['用户名']=id
temporally['密码']=Password
id_password.insert(j-1,temporally)
i+=1
break
if i>0:
print('修改成功')
else:
print('用户名或密码错误')
def traversal(book,borrowing):
i=0
list1=[]
for temporary in book:
if temporary['书名']==borrowing or temporary['作者']==borrowing:
print(temporary)
list1.append(temporary)
i+=1
if i==0:
print('很抱歉暂无该书籍')
return list1
else:
return list1
def remove_modification(temporally_list,i):
if i==1:
if type(temporally_list)==list:
for temporally in temporally_list:
pass
else:
temporally=temporally_list
for temporally_book in book:
if temporally['书名']==temporally_book['书名'] and temporally['作者']==temporally_book['作者']:
print(temporally_book)
book.remove(temporally_book)
break
while True:
receive=int(input('\n1.书名\n2.作者\n3.库存\n4.结束修改\n请选择你要修改的数据:'))
if receive==1:
NewName_book=input('请输入新的书名:')
temporally_book['书名']=NewName_book
elif receive==2:
new_name=input('请输入新的作者名:')
temporally_book['作者']=new_name
elif receive==3:
new_number=int(input('请输入新的库存数量:'))
temporally_book['数量']=new_number
elif receive==4:
book.insert(0,temporally_book)
print('修改成功')
break
else:
print('选择错误,请重新选择')
elif i==2:
for temporally in temporally_list:
pass
for temporally_book in book:
if temporally['书名']==temporally_book['书名'] and temporally['作者']==temporally_book['作者']:
print(temporally)
validation=input('是否删除(y删除其他任意键取消删除):')
if validation=='y' or validation=='Y':
book.remove(temporally_book)
print('删除成功')
break
else:
break
def add():
while(1):
nwe={}
f=0
new_bookName=input('请输入你本次添加的书籍名称:')
new_name=input('请输入你本次添加的书籍作者:')
nwe_number=int(input('请输入你本次添加的书籍数量'))
for temporally in book:
if temporally['书名']==new_bookName and temporally['作者']==new_name:
print(temporally)
f=1
break
if f==0:
nwe['书名']=new_bookName
nwe['作者']=new_name
nwe['数量']=nwe_number
book.append(nwe)
print('添加成功')
validation=input('是否继续添加(按N结束添加,其他任意键继续添加):')
if validation=='n' or validation=='N':
print('已退出添加')
break
else:
validation=input('已有该书籍(按N结束添加,其他任意键继续添加):')
if validation=='n' or validation=='N':
print('已退出添加')
break
def Borrowing_return(temporally_book,i):
print(temporally_book)
if i==1:
number=int(input('请输入你要借阅的数量:'))
if temporally_book['数量']>=number:
book.remove(temporally_book)
borrowing_book.append(temporally_book)
temporally_book['数量']-=number
book.insert(0,temporally_book)
print('借阅成功')
else:
print('很抱歉,本书库存不足')
elif i==2:
number_retrn=int(input('请输入你要归还的数量:'))
if temporally_book['数量']>=number_retrn:
for temporally in book:
if temporally['书名']==temporally_book['书名'] and temporally['作者']==temporally_book['作者']:
book.remove(temporally)
break
borrowing_book.remove(temporally_book)
temporally_book['数量']+=number_retrn
book.insert(0,temporally_book)
else:
print('很抱歉,该书籍并未借出这么多')
state=True
state_administrator=True
state_user=True
while state:
choose=int(input('---欢迎进入图书管理系统---\n---1.登录\n---2.修改账户\n---3.退出系统\n--请选择你的操作:'))
if choose==1:
i=3
while i>0:
i-=1
id=input('请输入用户名:')
password=input('请输入密码:')
validation=log_in(id,password)
if validation==1:
while state_administrator:
chooose_administrator=int(input('---欢迎进入图书管理系统(管理员版)---\n---1.修改书籍\n---2.删除书籍\n---3.查找书籍\n---4.查看所有书籍\n---5.添加书籍\n---6.退出系统\n---请选择你的操作'))
if chooose_administrator==1:
borrowing=input('请输入你要修改的书籍的书名或作者:')
temporally=traversal(book,borrowing)
if len(temporally)>0:
j=0
for ch in temporally:
j+=1
if j==1:
remove_modification(temporally,1)
else:
while True:
recording=0
borrowing_modification=input('请选择你要修改书籍的书名或作者:')
for temporally_book in temporally:
if borrowing_modification==temporally_book['书名'] or borrowing_modification==temporally_book['作者']:
remove_modification(temporally_book,1)
recording+=1
break
if recording==0:
print('选择错误,请选择正确的书名或作者')
else:
break
else:
print('很抱歉,暂无该书籍')
elif chooose_administrator==2:
deletion=input('请输入你要删除的书籍的书名或作者:')
temporally=traversal(book,deletion)
if len(temporally)>0:
j=0
for ch in temporally:
j+=1
if j==1:
remove_modification(temporally,2)
else:
while True:
recording=0
borrowing_2=input('请选择你要删除书籍的书名或作者:')
for ch in temporally:
if borrowing_2==temporally['书名'] or borrowing_2==temporally['作者']:
remove_modification(temporally,2)
recording+=1
break
if recording==0:
print('选择错误,请选择正确的书名或作者')
else:
break
else:
print('很抱歉,暂无该书籍')
elif chooose_administrator==3:
target=input('请输入你要查找的书籍的书名或作者:')
temporally=traversal(book,target)
if temporally>0:
for temporally_book in temporally:
print(temporally)
else:
print('很抱歉,暂无该书籍信息')
elif chooose_administrator==4:
for temporally_book in book:
print(temporally_book)
elif chooose_administrator==5:
add()
elif chooose_administrator==6:
print('退出成功')
i=-1
state_administrator=False
elif validation==2:
while state_user:
choose_user=int(input('---欢迎进入图书管理系统---\n---1.借阅书籍\n---2.归还书籍\n---3.查找书籍\n---4.查看所有书籍\n---5.退出系统\n---请选择你的操作'))
if choose_user==1:
borrowing=input('请输入你要借阅的书籍的书名或作者:')
temporally=traversal(book,borrowing)
if len(temporally)>0:
j=0
for ch in temporally:
j+=1
if j==1:
Borrowing_return(temporally,1)
else:
while True:
recording=0
borrowing_modification=input('请选择你要修改书籍的书名或作者:')
for temporally_book in temporally:
if borrowing_modification==temporally_book['书名'] or borrowing_modification==temporally_book['作者']:
Borrowing_return(temporally_book,1)
recording+=1
break
if recording==0:
print('选择错误,请选择正确的书名或作者')
else:
break
else:
print('很抱歉,暂无该书籍')
elif choose_user==2:
borrowing=input('请输入你要借阅的书籍的书名或作者:')
temporally=traversal(borrowing_book,borrowing)
if len(temporally)>0:
j=0
for ch in temporally:
j+=1
if j==1:
Borrowing_return(temporally_book,2)
else:
while True:
recording=0
borrowing_modification=input('请选择你要修改书籍的书名或作者:')
for temporally_book in temporally:
if borrowing_modification==temporally_book['书名'] or borrowing_modification==temporally_book['作者']:
Borrowing_return(temporally_book,2)
recording+=1
break
if recording==0:
print('选择错误,请选择正确的书名或作者')
else:
break
elif choose_user==3:
target=input('请输入你要查找的书籍的书名或作者:')
temporally=traversal(book,target)
if temporally>0:
for temporally_book in temporally:
print(temporally)
else:
print('很抱歉,暂无该书籍信息')
elif choose_user==4:
for temporally_book in book:
print(temporally_book)
elif choose_user==5:
print('退出成功')
i=-1
state_user=False
else:
print('用户名或密码错误,你还有{}次机会'.format(i))
if i==0:
print('输入已达最大次数,账户已冻结')
state=False
elif choose==2:
Modify_the_user()
else:
print('选择错误,请重新选择')
print('退出成功')
|