• 用列表实现一个简单的图书管理系统 python


    #coding=utf-8

    book_list=[]  #图书馆所有书

    unborrowed_book=[]  #可借阅的书

    borrowed_book=[]  #已经借出去的书

    def add():  #添加书

        global book_list

        global unborrowed_book

        book_name=raw_input(u"请输入要添加的书名:".encode("gbk"))

        book_list.append(book_name)

        unborrowed_book.append(book_name)

        print u"添加书成功"

    def borrow_book():  #借书

        global unborrowed_book

        global borrowed_book

        while 1:

            book_name=raw_input(u"请输入要借的书名:".encode("gbk"))

            if book_name in unborrowed_book:

                unborrowed_book.remove(book_name)        

                borrowed_book.append(book_name)

                print u"借书成功"

                break

            else:

                print u"抱歉,您要借的书不存在!"

                continue_back=raw_input(u"继续借书请输入:c 返回主菜单请输入:b ".encode("gbk"))

                if continue_back.lower()=="c":

                    continue

                elif continue_back.lower()=="b":

                    break

                else:

                    print u"输入数据无效"            

    def return_book():  #还书

        global borrowed_book

        global unborrowed_book

        while 1:

            book_name=raw_input(u"请输入要还的书名:".encode("gbk"))

            if book_name in borrowed_book:

                borrowed_book.remove(book_name)

                unborrowed_book.append(book_name)

                print u"还书成功"

                break

            else:

                print u"您输入的书名不是此图书馆的"

                continue_back=raw_input(u"继续还书请输入:c 返回主菜单请输入:b ".encode("gbk"))

                if continue_back.lower()=="c":

                    continue

                elif continue_back.lower()=="b":

                    break

                else:

                    print u"输入数据无效"    

    menu_info='''

    添加书--请输入:1

    借书--请输入:2

    查看可借阅的书--请输入:3

    查看借出去的书--请输入:4

    还书--请输入:5

    查看所有书--请输入:6

    退出--请输入:q

    '''

    import sys

    print menu_info.decode("utf-8")

    while True:    

        command=raw_input(u"请输入您要做的操作选项:".encode("gbk"))

        if command=="1":

            add()

        elif command=="2":

            borrow_book()

        elif command=="3":

            if unborrowed_book==[]:

                print u"抱歉,没有可以借的书了!"

            else:

                print u"可借阅的书:",unborrowed_book    

        elif command=="4":

            if borrowed_book==[]:

                print u"没有借出去的书!"

            else:

                print u"借出去的书:",borrowed_book

        elif command=="5":

            return_book()

        elif command=="6":

            if book_list==[]:

                print u"图书馆还没有书,赶快去添加吧!"

            else:

                print u"图书馆所有的书:",book_list

        elif command=="q":

            sys.exit()

        else:

            print u"输入数据无效!"

  • 相关阅读:
    bzoj2763 [JLOI]飞行路线 分层图最短路
    [模板]分块/可修改莫队 (数颜色种类)
    gcd步数
    洛谷2378 因式分解 字符串
    bzoj1090 字符串折叠
    洛谷1034 NOIP2002 矩形覆盖
    Codeforces#441 Div.2 四*题
    SPFA的小优化
    洛谷1073 NOIP2009 最优贸易
    bzoj2100 [Usaco2010 DEC]Apple Delivery苹果贸易
  • 原文地址:https://www.cnblogs.com/reyinever/p/8053597.html
Copyright © 2020-2023  润新知