Python 簡易版圖書管理系統

"""
圖書管理系統
"""
import randomapp

# books={書名:剩餘數量, 書名:剩餘數量}
import timedom

books = {"防脫髮指南": 5, "頸椎康復指南": 3, "從刪庫到跑路": 0}
# students_books=[name,{書}]
students_books = {"趙路遙": []}orm


class book(object):
"""先傳一個書名,之後可根據須要傳 開始借書時間,書的詳細信息,以及以前借書的人等等"""rem

def __init__(self, bookname):
super(book, self).__init__()
self.bookname = booknameget

def getBookName(self):
return self.booknameinput


if __name__ == "__main__":
print("*" * 50)
print("歡迎來到遙遙哥的圖書館".center(50))
print("*" * 50)
while True:
choices = input(""" 請選擇你所須要的功能
1.查詢書籍 2.借書 3.還書 4.顯示全部書籍 5.查詢用戶所借的書 6.退出系統:""")
if choices == '1':
# 查詢書籍
print('--------查詢書籍---------')
search_book = input('請輸入要查詢的書籍名稱:')
# 遍歷books
for book in books.keys():
if search_book in book:
print("正在查找,請稍等")
time.sleep(1)
if books[search_book] > 0:
print("你說查找的書,目前還有{}本".format(books[search_book]))
break
else:
print("你所查找的書,已經借完,請過段時間以後再來")
break
else:
print("對不起你所輸入的書不存在,可聯繫管理員補充")it

elif choices == '2':
# 借書
print("歡迎來到借書頁面".center(50))
flag = True
while flag:
user_name = input("請輸入用戶名")
borrow_book = input("請輸入你所借的書名")
for book in books.keys():
if borrow_book == book:
if user_name in students_books.keys():
if books[borrow_book] > 0:
if borrow_book not in students_books[user_name]:
print(r"你已經借書<<{}>>".format(borrow_book))
students_books[user_name].append(borrow_book)
books[borrow_book] -= 1
print(r"如今<<{}>>,剩餘{}本".format(borrow_book, books[borrow_book]))
flag = False
break
else:
print("對不起,你已經借了一本")
flag = False
break
else:
print("對不起你所借的書剩餘{}本,請下次再來".format(books[borrow_book]))
flag = False
break
else:
students_books[user_name] = []
students_books[user_name].append(borrow_book)
books[borrow_book] -= 1
print(r"新用戶( {} )已經借書<< {} >>,目前此書剩餘{}本".format(user_name, borrow_book, books[borrow_book]))
flag = False
breakform

else:
print("對不起你所查找的書,不存在,請聯繫管理員更新")class

elif choices == '3':
flag=True
while flag:
user_name = input("請輸入你的名字")
repay_book = input("情輸入你所要還的書")
for name in students_books.keys():
#先去判斷有沒有這我的
if name==user_name:
#判斷有沒有這本書在不在該用戶
if repay_book in students_books[name]:
#判斷此本書書否在圖書館庫裏面
if repay_book in books.keys():
books[repay_book]+=1
students_books[name].remove(repay_book)
print("正在還書,請稍等")
time.sleep(1)
print("你已經還書了,這本書數量爲{}".format(books[repay_book]))
flag=False
break
else:
print("此本書不在圖書館庫裏面,請從新輸入")
break
else:
print("你所輸入的書,並在你的借書目錄裏面,請從新輸入")
break
else:
print("對不起你所輸入的人不存在,請從新輸入")import

elif choices == '4': # 顯示全部書籍 print("圖書館目前所藏書籍以下:") for bookkey, bookvalue in list(books.items()): print(r"<<{}>>目前還有 {} 本".format(bookkey, bookvalue)) time.sleep(0.5) elif choices=='5': username=input(" 請輸入你要查詢的用戶名") for stu in students_books.keys(): if username== stu: print("{}所借的書有{}".format(user_name,students_books[username])) else: print("你查找的用戶不在") elif choices == '6': choice = ("肯定是否退出,確認請輸入yes,不然請輸入no") if choice == 'yes': print("感謝你的使用,再見") break else: print('輸入錯誤請從新輸入....')

相關文章
相關標籤/搜索