用python尝试的第一段代码,图书馆维护书本,新增、查询、修改、删除等操作

##############图书馆借书程序编写##########
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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值