python 学习笔记3

学员管理系统

# 显示功能界面
info = []
def display():
    print('请选择功能----------')
    print('1、添加学员')
    print('2、删除学员')
    print('3、修改学员')
    print('4、查询学员')
    print('5、显示所有学员')
    print('6、退出系统')
    print('-'*20)
def add():
    new_id = input('请输入学号')
    new_name = input('请输入姓名')
    new_tel = input('请输入手机号')

    global info
    for i in info:
        if new_name == i['name']:
            print('目前学员已经存在')
            return
    info_dict = {}
    info_dict['id'] = new_id
    info_dict['name'] = new_name
    info_dict['tel'] = new_tel
    info.append(info_dict)
    print(info)
def delete():
    global info
    delete_name = input('请输入要删除的学员')
    for i in info:
        if delete_name == i['name']:
            info.remove(i)
            break;
    else:
        print('学员不存在')
    print(info)
def modify():
    new_name = input('请输入姓名')
    global info
    for i in info:
        if new_name == i['name']:
            i['tel'] = input('请输入新的手机号')
            break
    else:
        print('学员不存在')
    print(info)
def search_info():
    search_name = input('请输入学员姓名')
    for i in info:
        if search_name == i['name']:
            print('信息如下----------')
            print(f"学号{i['id']},姓名{'i[name]'},手机号{i['tel']}")
            break;
    else:
        print('学员不存在')
def print_all():
    print(f'学号/t姓名/t手机号')
    for i in info:
        print(f"{i['id']}/t{i['name']}/t{i[tel]}")
while True:
    display()
    user_num = int(input('请输入功能'))
    if user_num == 1:
        add()
    elif user_num == 2:
        delete()
    elif user_num == 3:
        modify()
    elif user_num == 4:
        search_info()
    elif user_num == 5:
        print_all()
    elif user_num == 6:
        exit_flag = input('确定要退出吗? yes or no')
        if exit_flag == 'yes':
            break
    else:
         print('请输入正确编号')

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值