##############图书馆借书程序编写##########
books={1:'English',2:'Chinese',3:'Math',4:'physics',5:'Chemistry',6:'biology'}
#print(books)
name=input('please input your name: ')
print('hello!',name)
books_len=len(books)
print(name,'welcome! we have ',books_len,'books')
print(books)
print('########### choose your option now ##########')
option=('1.all booklist\n' '2.find the location of the book\n' '3.change the number of the book\n' '4.delete bool\n' '5.add book\n' '6.exit current page\n')
print(option)
option_num = input()
if option_num == '1':
print(books)
elif option_num == '2':
print(books.values())
print('please choose your book ')
book_name = input()
if book_name in books.values():
book_num=list(books.keys())[list(books.values()).index(book_name)]
print(book_num)
print('The location of the %s book is number %s!' %(book_name, book_num))
else:
print('can not find this bookname!')
elif option_num == '3':
book_name=input('please input the book which you will change number!')
if book_name in books.values():
book_num=list(books.keys())[list(books.values()).index(book_name)]
newbook_num= int(input('please input new book_number '))
if newbook_num in books.keys():
print('sorry,the number already exist!please input again!')
else:
books[newbook_num]=books.pop(book_num)
print("Change Success!")
print(books)
print('can not find this bookname!')
elif option_num =='4':
delete_books_name=input('please input which book you will delete ')
if delete_books_name not in books.values():
print('can not find this bookname!')
else:
book_num=list(books.keys())[list(books.values()).index(delete_books_name)]
print(book_num)
books.pop(book_num)
print('Delete Success!',books)
elif option_num=='5':
addkey=input('please input addkey ')
if int(addkey) not in books.keys():
addbook_name=input('please input new bookname ')
print('add Success!')
books[addkey]=addbook_name
print(books)
else:
print('sorry,the number already exist!please input again!')
elif option_num=='0':
print('exit the system!')
else:
print('please input correct number!')
参考了别人的,但不完全一致,也算是自己有一些尝试跟思考。
查看图书列表、查找图书编号、更新图书编号、删除书本、新增书本、退出查询
参考链接如下:
https://www.liaoxuefeng.com/discuss/969955749132672/1434054322815010