studentList = [["tsy", "男", "123"]] tempList = [] def add_student(): temp = [] initList() name = input("请输入姓名:") if search_user(name) != -1: print("用户已存在") return sex = input("请输入性别:") phone = input("请输入电话:") temp.append(name) temp.append(sex) temp.append(phone) tempList.append(temp) def del_user(name): initList() if search_user(name) == -1: print("未找到此用户") return tempList.remove(tempList[search_user(name)]) def search_user(name): for i in range(len(studentList)): if studentList[i][0] == name: return i else: return -1 def update_user(): initList() temp = [] name = input("请输入姓名:") if search_user(name) == -1: print("未找到此用户") return sex = input("请输入性别:") phone = input("请输入电话:") temp.append(name) temp.append(sex) temp.append(phone) tempList[search_user(name)] = temp def quaryAll(): return studentList def saveInfo(): studentList.clear() studentList.extend(tempList) tempList.clear() print("操作已保存") def initList(): tempList.clear() tempList.extend(studentList) def init(): print("请选择如下功能\n1:添加学员\n2:删除\n3:修改该学员\n4:查询学员\n5:显示所有学员\n6:保存学员信息\n7:退出") action = int(input("请输入您需要的功能序号:")) while action != 7: if action == 1: add_student() elif action == 2: name = input("输入要删除的学生姓名:") del_user(name) elif action == 3: update_user() elif action == 4: name = input("输入要查询的学生姓名:") res = studentList[search_user(name)] if search_user(name) != -1 else "未找到" print(res) elif action == 5: print(quaryAll()) elif action == 6: saveInfo() action = int(input("请输入您需要的功能序号:")) if __name__ == '__main__': init()