# 建立一个列表 list_stuInf = [] # 添加功能 def add() : # 循环可添加多个学员 while True: # 添加学员名字 字符串类型 name = input('请输入添加的学员姓名,q停止添加:') # 停止添加操作 输入q停止 否则继续 if name == 'q': break else: # 将学员姓名添加到列表中 list_stuInf.append(name) print(list_stuInf) continue # 修改功能 def modify(): # 用索引的方法输出所有学员 for x in range(0, len(list_stuInf)): rs = list_stuInf[x] x = x + 1 print('学号:%s学员姓名:%s' % (x, rs)) while True: # 选择要修改的学员索引 y = int(input('请输入要修改的学号:')) # 判断索引是否在范围 if y > x: y = int(input('学号不存在,请重新输入:')) else: #修改学员姓名 a = input('学员姓名修改为:') y = y - 1 list_stuInf[y] = a break # 删除功能 def delInf(): # 用索引的方法输出所有学员 for x in range(0, len(list_stuInf)): rs = list_stuInf[x] x = x + 1 print('学号:%s学员姓名:%s' % (x, rs)) # 选择要修改的学员索引,判断索引是否在范围 while True: # 选择要修改的学员索引 z = int(input('请输入要删除的学号:')) # 判断索引是否在范围 if z > x: y = int(input('学号不存在,请重新输入:')) else: # 删除学员姓名 z = z - 1 del list_stuInf[z] break #查询功能 def display(): for x in range(0, len(list_stuInf)): rs = list_stuInf[x] x = x + 1 print('学号:%s学员姓名:%s' % (x, rs)) while True: print('学生管理系统1.0版本:') print('1.添加学员') print('2.修改学员') print('3删除学员 3.1删除全部学员') print('4.查询学员') print('0.退出') select = int(input('您的选择是:')) while select < 0 or select >4: select = float(input('选项有误,请重新')) if select == 1: #调用函数 add() if select == 2: modify() if select == 3: delInf() if select == 4: display() if select == 0: print('欢迎下次使用!') break