判断和循环编程实战


1、编写一个简单的图书管理系统

2、实现基本的增、删、改、查功能

3、尽量在程序中使用学到的知识

BOOKS = []
while True:
    print('-' * 50)
    print('欢迎使用图书管理系统,请您输入数字指令进行管理!')
    print('-' * 50)
    print('增加图书【1】删除图书【2】修改图书【3】查看图书【4】')
    print('-' * 50)
    num = input('请您输入数字指令:')
    if num == '1':
        book = input('请您输入书名:')
        BOOKS.append(book)
        print('{}增加成功!'.format(book))
    elif num == '2':
        book = input('请您输入需要删除的书名:')
        if book in BOOKS:
            BOOKS.remove(book)
            print('{}删除成功!'.format(book))
        else:
            print('您输入的书名不存在!')
    elif num == '3':
        book = input('请您输入需要修改的书名:')
        if book in BOOKS:
            newbook = input('请您输入新的书名:')
            BOOKS[BOOKS.index(book)] = newbook
            print(f'{book}已修改为{newbook}!')
        else:
            print('您输入的书名不存在!')
    elif num == '4':
        if BOOKS == []:
            print('目前没有图书!')
        else:
            for book in BOOKS:
                print(f'书名:{book}')
    else:
        print('您的输入错误!')

results matching ""

    No results matching ""