实现学员管理系统

实现学员管理系统”””班级学员管理系统需求:简单的设计一下首页。1、添加学员信息,设计简单的页面2、删除学员信息,学员信息为空则不执行操作3、修改学员信息,学员信息为空不执行操作(当修改的学员的姓名不在列表中时返回错误)4、查找学员信息,把学员信息,依次输出在终端页面”””Student_List=[]whileTrue:print(”)print(‘–…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

"""
班级学员管理系统
需求:
简单的设计一下首页。
1、添加学员信息,设计简单的页面
2、删除学员信息,学员信息为空则不执行操作
3、修改学员信息,学员信息为空不执行操作(当修改的学员的姓名不在列表中时返回错误)
4、查找学员信息,把学员信息,依次输出在终端页面
"""

Student_List = []
while True:
    print('   ')
    print('--------------欢迎使用学生管理系统------------')
    print('---------------1.添加学员信息-----------------')
    print('---------------2.删除学员信息-----------------')
    print('---------------3.修改学生信息-----------------')
    print('---------------4.查看学生信息-----------------')
    print('---------------0.退出系统---------------------')
    number = int(input('请输入你想要的操作:'))
    # 添加学员信息
    if number == 1:
        while True:
            name = input('请输入添加的学员姓名:')
            age = input('请输入添加学员年龄:')
            place = input('请输入添加学员籍贯:')
            stu_list = [name, age, place]
            Student_List.append(stu_list)
            choice = input('还要继续添加吗? y/n')
            if choice == 'n':
                break
    # 删除学员信息
    elif number == 2:
        while True:
            if len(Student_List) == 0:
                print('错误:没有学员信息')
                break
            else:
                for idx, stu in enumerate(Student_List):
                    idx += 1
                    name = stu[0]
                    age = stu[1]
                    place = stu[2]
                    print('* 学号: %s | 学生姓名: %s | 年龄: %s | 籍贯:%s' % (idx, name, age, place))
                cho = int(input('输入你想删除学员的学号:'))
                choi = input('确定要删除%s的信息吗?(y/n):'%Student_List[cho-1][0])
                if choi == 'y':
                    Student_List.pop(cho - 1)
                    print('删除成功!')
                choice = input('还要继续删除吗? y/n')
                if choice == 'n':
                    break
                else:
                    print('返回首页!')


    # 修改学员信息
    elif number == 3:
        while True:
            if len(Student_List) == 0:
                print('错误:没有学员信息')
                break
            else:
                for idx, stu in enumerate(Student_List):
                    idx += 1
                    name = stu[0]
                    age = stu[1]
                    place = stu[2]
                    print('* 学号: %s | 学生姓名: %s | 年龄: %s | 籍贯:%s' % (idx, name, age, place))
                select = int(input('请输入你想通过什么来修改学员信息1.学号2.姓名'))
                if select == 1:
                    student_number = int(input('输入你想修改学员的学号:'))
                    if student_number > len(Student_List):
                        print('不好意思,你想修改的这个人不存在')
                        break
                    name = input('请输入要修改的学员姓名:')
                    age = input('请输入要修改的学员年龄:')
                    place = input('请输入要修改的学员籍贯:')
                    stu_list = [name, age, place]
                    Student_List[student_number - 1] = stu_list
                    print('修改成功!')
                elif select == 2:
                    name = input('请输入将要修改的学员姓名:')
                    count = 0
                    for count, stu in enumerate(Student_List):
                        count += 1
                        if name == stu[0]:
                            break
                    if count >= len(Student_List):
                        print(name, '学生不存在')
                        break
                    name1 = input('请输入要修改的学员姓名(无需修改请按 0):')
                    age = input('请输入要修改的学员年龄(无需修改请按 0):')
                    place = input('请输入要修改的学员籍贯(无需修改请按 0):')
                    for idx, stu in enumerate(Student_List):
                        idx += 1
                        if name == stu[0]:
                            if name1 != '0':
                                stu[0] = name1
                            elif age != '0':
                                stu[1] = age
                            elif place != '0':
                                stu[2] = place
                            break
                choice = input('还要继续修改吗? y/n')
                if choice == 'n':
                    break
    # 查看学员的信息
    elif number == 4:
        if len(Student_List) == 0:
            print('错误:没有学员信息')
        else:
            for idx, stu in enumerate(Student_List):
                idx += 1
                name = stu[0]
                age = stu[1]
                place = stu[2]
                print('* 学号: %s | 学生姓名: %s | 年龄: %s | 籍贯:%s' % (idx, name, age, place))
    elif number == 0:
        print('感谢使用!')
        break
    else:
        while True:
            print('不要输入其他数字,否则宕机后果自负!')












 改成函数

Student_List = []


def welcome():
    print('   ')
    print('--------------欢迎使用学生管理系统------------')
    print('---------------1.添加学员信息-----------------')
    print('---------------2.删除学员信息-----------------')
    print('---------------3.修改学生信息-----------------')
    print('---------------4.查看学生信息-----------------')
    print('---------------0.退出系统---------------------')


def add():
    # 添加学员信息
    while True:
        name = input('请输入添加的学员姓名:')
        age = input('请输入添加学员年龄:')
        place = input('请输入添加学员籍贯:')
        stu_list = [name, age, place]
        Student_List.append(stu_list)
        choice = input('还要继续添加吗? y/n')
        if choice == 'n':
            break


def delete():
    while True:
        if len(Student_List) == 0:
            print('错误:没有学员信息')
            break
        else:
            for idx, stu in enumerate(Student_List):
                idx += 1
                name = stu[0]
                age = stu[1]
                place = stu[2]
                print('* 学号: %s | 学生姓名: %s | 年龄: %s | 籍贯:%s' % (idx, name, age, place))
            cho = int(input('输入你想删除学员的学号:'))
            choi = input('确定要删除%s的信息吗?(y/n):' % Student_List[cho - 1][0])
            if choi == 'y':
                Student_List.pop(cho - 1)
                print('删除成功!')
            choice = input('还要继续删除吗? y/n')
            if choice == 'n':
                break


def alter():
    while True:
        if len(Student_List) == 0:
            print('错误:没有学员信息')
            break
        else:
            for idx, stu in enumerate(Student_List):
                idx += 1
                name = stu[0]
                age = stu[1]
                place = stu[2]
                print('* 学号: %s | 学生姓名: %s | 年龄: %s | 籍贯:%s' % (idx, name, age, place))
            select = int(input('请输入你想通过什么来修改学员信息1.学号2.姓名'))
            if select == 1:
                student_number = int(input('输入你想修改学员的学号:'))
                if student_number > len(Student_List):
                    print('不好意思,你想修改的这个人不存在')
                    break
                name = input('请输入要修改的学员姓名:')
                age = input('请输入要修改的学员年龄:')
                place = input('请输入要修改的学员籍贯:')
                stu_list = [name, age, place]
                Student_List[student_number - 1] = stu_list
                print('修改成功!')
            elif select == 2:
                name = input('请输入将要修改的学员姓名:')
                count = 0
                for count, stu in enumerate(Student_List):
                    count += 1
                    if name == stu[0]:
                        break
                if count >= len(Student_List):
                    print(name, '学生不存在')
                    break
                name1 = input('请输入要修改的学员姓名(无需修改请按 0):')
                age = input('请输入要修改的学员年龄(无需修改请按 0):')
                place = input('请输入要修改的学员籍贯(无需修改请按 0):')
                for idx, stu in enumerate(Student_List):
                    idx += 1
                    if name == stu[0]:
                        if name1 != '0':
                            stu[0] = name1
                        elif age != '0':
                            stu[1] = age
                        elif place != '0':
                            stu[2] = place
                        break
            choice = input('还要继续修改吗? y/n')
            if choice == 'n':
                break


def examine():
    # 查看学员的信息
    if len(Student_List) == 0:
        print('错误:没有学员信息')
    else:
        for idx, stu in enumerate(Student_List):
            idx += 1
            name = stu[0]
            age = stu[1]
            place = stu[2]
            print('* 学号: %s | 学生姓名: %s | 年龄: %s | 籍贯:%s' % (idx, name, age, place))


def thank():
    print('感谢使用!')


def other():
    while True:
        print('不要输入其他数字,否则宕机后果自负!')


while True:
    welcome()
    number = int(input('请输入你想要的操作:'))
    if number == 1:
        add()
    elif number == 2:
        delete()
    elif number == 3:
        alter()
    elif number == 4:
        examine()
    elif number == 0:
        thank()
        break
    else:
        other()




 老师的

Student_List = []
def add_stu():
    print('-------------------添加学员信息-------------------')
    while True:
        name = input(' * 请输入学员姓名:')
        age = input(' * 请输入学员年龄:')
        address = input(' * 请输入学员家庭地址:')
        stu_list = [name, age, address]
        Student_List.append(stu_list)
        choice = input('添加成功,是否继续添加? (y/n) :')
        if choice == 'n':
            break

def del_stu():
    if len(Student_List) == 0:
        print('* 错误:没有学员信息')
    else:
        print('* 1、删除所有学员信息')
        print('* 2、根据学号删除学员信息')
        choice1 = int(input('请输入您要执行的操作:'))
        if choice1 == 1:
            for a in range(len(Student_List)):
                Student_List.pop()
                print('* 删除成功!')
        else:
            look_stu()
            cho = int(input('* 请输入您要删除的学生学号:'))
            choi = input('确定要删除%s的信息吗? (y/n): ' % Student_List[cho - 1][0])
            if choi == 'y':
                del Student_List[cho - 1]
                print('删除成功!')
            else:
                print('返回首页!')

def look_stu():
    print('-----------------学员信息------------------')
    if len(Student_List) == 0:
        print('错误:没有学员信息')
    else:
        for idx, stu in enumerate(Student_List):
            idx += 1
            name = stu[0]
            age = stu[1]
            address = stu[2]
            print('* 学号:%s | 学生姓名:%s  | 年龄:%s  | 家庭住址:%s' % (idx, name, age, address))
            print('*-----------------------------------------------------')

def upd_stu():
    if len(Student_List) == 0:
        print('* 没有学员信息')
    else:
        look_stu()
        idx = int(input('* 请输入您要修改的学员学号:'))
        idx -= 1
        new_name = input('* 请输入修改后的学员姓名:')
        new_age = input('* 请输入修改后的学员年龄:')
        new_address = input('* 请输入修改后的学员家庭住址:')
        student_list = Student_List[idx]
        student_list[0] = new_name
        student_list[1] = new_age
        student_list[2] = new_address
        print('修改成功')

while True:
    #首页
    print('-------------学员管理系统--------------')
    print(' ')
    print('* 1.添加学员信息 ')
    print('* 2.修改学员信息 ')
    print('* 3.删除学员信息 ')
    print('* 4.查看学员信息 ')
    print('* 0.退出系统 ')
    print('---------------------------------------')
    num = int(input('* 请选择您要执行的操作:'))
    if num == 1:
        add_stu()
    elif num == 2:
        upd_stu()
    elif num ==3:
        del_stu()
    elif num == 4:
        look_stu()
    else:
        print('* 感谢使用!!!')
        break

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/191283.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • dubbo框架RPC过程详解「建议收藏」

    转载地址:http://www.cnblogs.com/LBSer/p/4853234.html你应该知道的RPC原理  在学校期间大家都写过不少程序,比如写个helloworld服务类,然后本地调用下,如下所示。这些程序的特点是服务消费方和服务提供方是本地调用关系。  而一旦踏入公司尤其是大型互联网公司就会发现,公司的系统都由成千上万大大小小的服务组成,各服务部署在不同的机器上,由不同的

    2022年4月11日
    53
  • linux激活环境变量_Pycharm激活

    linux激活环境变量_Pycharm激活1.修改/etc/hosts文件[root@foundation25Desktop]#vim/etc/hosts进入后,将0.0.0.0account.jetbrains.com添加到最后127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1lo…

    2025年6月30日
    5
  • intellij idea上传项目到码云

    intellij idea上传项目到码云

    2021年5月16日
    138
  • 前端盲水印_前端代码review

    前端盲水印_前端代码review需求给图片加上看不到的水印,当通过其他的方式可以清楚的看到图片中暗藏的水印,以此方式追溯到泄密的人解决办法利用canvas实现图片和水印的绘制,具体过程如下:新建canvas,宽度和高度取要加水印的图片的宽度和高度 在该canvas上绘制要添加的水印文字,文字透明度设置要特别的低,但是当水印透明度小于等于0.003,不可恢复到水印。所以我们设置透明度要不得低于0.003 将该canvas转成img(为什么canvas要转成img?之前遇到canvas在移动端无法长按出现保存、转发等操作)

    2025年6月23日
    4
  • offsetof(s,m)解析「建议收藏」

    offsetof(s,m)解析「建议收藏」使用实例:typedefstruct{constAVClass*class;char*expr_str;AVExpr*expr;doublevar_values[VAR_VARS

    2022年7月2日
    30
  • ubuntu卸载cuda10.2_dpkg强制卸载软件

    ubuntu卸载cuda10.2_dpkg强制卸载软件一、参考资料CUDA、CUDNN在Ubuntu下的安装及配置二、注意事项用deb方式安装CUDA,会附带安装显卡驱动;用run方式安装CUDA,需要提前安装好显卡驱动;安装显卡驱动的时候,最好安装高版本的,这样不会受cuda版本的影响;三、run方式卸载用run方式安装的CUDA和驱动#uninstallcuda#第一行命令不要忘记要加上perl命令,要不然会报错sudoperl/usr/local/cuda-X.Y/bin/uninstall_cuda_X.Y.pl

    2025年9月1日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号