python3基础-图书馆借阅系统-源码

一、介绍

学习python3的过程中,用作练习的单文件(.py)程序,在命令行界面进行交互,
功能:

  1. All book lists
  2. Find the location of the book
  3. Change the number of the book
  4. Delete book
  5. Add book
  6. Exist current page

二、源码

没什么好上传的,源码就直接贴出来了,大家给个赞就好,哈哈哈

'''
Descripttion: py06 python3基础-图书馆借阅系统-源码
version: 1.0.0
Author: FENG
Date: 2022-02-14 15:12:41
LastEditors: FENG
LastEditTime: 2022-02-18 10:54:58
'''
# 定义图书元组序列
books = {
    1: 'English',
    2: 'Chinese',
    3: 'Math',
    4: 'Physics',
    5: 'Chemistry',
    6: 'Biology',
    7: 'Chinese'
}


# 定义一个函数,封装展示所有书籍的操作
def showAllBooks():
    print('-----书籍列表---------')
    for index, value in books.items():
        print(index, value)
    print()


# 输入管理员账号
adminName = input('请输入您的账户名称:')

# 打印欢迎信息
print('------------欢迎您,{0}---------'.format(adminName))

book_lens = len(books)

print('图书馆现存数据数量:{0}'.format(book_lens))
showAllBooks()

options = '''
1. All book lists
2. Find the location of the book
3. Change the number of the book
4. Delete book
5. Add book
0. Exist current page
------------*------------
'''


# 定义一个函数,封装展示所有书籍的操作
def showAllFunc():
    print('-----功能列表---------')
    print(options)
    print()


print()


# 定义一个函数,封装是否继续操作的逻辑
def whether_continue():
    print()
    x = input("是否继续操作?(y/n)")
    if x == 'y':
        library_func()
    elif x == 'n':
        return
    else:
        print('输入错误!请重新选择')
        library_func()


# 定义函数


def library_func():
    showAllFunc()
    option_num = int(input('请输入您选择的功能:'))

    # 1. All book lists
    if option_num == 1:
        print('>>>所有书籍列表:')
        for index, value in books.items():
            print(index, value)

        print('>>>书籍列表结束')
        whether_continue()

    # 2. Find the location of the book
    elif option_num == 2:
        print('all books name:', books)
        book_name = input(
            'Enter your book name which`s location you want to known?')
        # 从元组中获取书籍的索引并加1
        if book_name in books.values():
            book_num = list(books.values()).index(book_name)
            print('{book_name}的编号是:{book_num}'.format(book_name=book_name,
                                                      book_num=book_num + 1))
        else:
            print('未查询到此书籍!')

        print('>>>检索书籍结束')
        whether_continue()

    # 3. Change the number of the book
    elif option_num == 3:
        old_book_num = int(input('请输入书籍的原编号:'))
        if old_book_num in books.keys():
            print('>>查询到书籍。')
            old_book_name = books[old_book_num]
            new_book_num = int(input('请输入书籍的新编号:'))
            books[new_book_num] = old_book_name
            books.pop(old_book_num)
            print('书籍编号变更成功')
        else:
            print('为查询到该书籍!')

        whether_continue()

    # 4. Delete book
    elif option_num == 4:
        showAllBooks()
        del_index = int(input('请输入您要删除的书籍的索引:'))
        if del_index in books.keys():
            books.pop(del_index)
            print('删除书籍成功')
        else:
            print('未查询到书籍!')

        whether_continue()

    # 5. Add book
    elif option_num == 5:
        showAllBooks()
        new_book_num = int(input('请您输入新书籍的编号:'))
        new_book_name = str(input('请您输入新书籍的名称:'))

        if new_book_num in books.keys():
            print('您输入的编号已经存在!')
        else:
            books[new_book_num] = new_book_name
            print('新书籍添加成功!')
            showAllBooks()
            whether_continue()
    # 0. Exist current page
    elif option_num == 0:
        print('Exit the current query system')
    else:
        print('未查询到您输入的功能!')
        whether_continue()


library_func()

三、运行截图

在这里插入图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值