You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.0 KiB
92 lines
3.0 KiB
student_list=[]
|
|
|
|
def show_menu():
|
|
print("请选择如下功能:")
|
|
print("1.添加学员:")
|
|
print("2.删除学员:")
|
|
print("3.修改学员信息:")
|
|
print("4.查询学员信息:")
|
|
print("5.显示所有学员信息:")
|
|
print("6.保存学员信息:")
|
|
print("7.退出系统:")
|
|
|
|
|
|
def add_student():
|
|
name=input("请输入您的姓名:")
|
|
sex=input("请输入您的性别:")
|
|
numbers=input("请输入您的电话:")
|
|
student_dict=dict()
|
|
student_dict["name"]=name
|
|
student_dict["sex"]=sex
|
|
student_dict["numbers"]=numbers
|
|
student_list.append(student_dict)
|
|
print(student_list)
|
|
|
|
def show_all_student():
|
|
for index,student_dict in enumerate(student_list):
|
|
student_id=index+1
|
|
print("姓名:{},性别:{},电话:{}".format(student_dict["name"],student_dict["sex"],student_dict["numbers"]))
|
|
|
|
def modify_student():
|
|
student_id = eval(input("请输入您要修改的学生学号:"))
|
|
student_no = student_id - 1
|
|
if 0 <= student_no < len(student_list):
|
|
current = student_list[student_no]
|
|
new_name = input("请输入修改后的姓名:")
|
|
new_sex = input("请输入修改后的性别:")
|
|
new_numbers= input("请输入修改后的电话:")
|
|
current["name"] = new_name
|
|
current["sex"] = new_sex
|
|
current["numbers"] = new_numbers
|
|
print("修改成功!")
|
|
else:
|
|
print("请输入合法的学号!")
|
|
|
|
def remove_student():
|
|
student_id = eval(input("请输入要删除的学生学号:"))
|
|
student_no = student_id - 1
|
|
if 0 <= student_no < len(student_list):
|
|
current = student_list.pop(student_no)
|
|
print("删除的数据", current)
|
|
else:
|
|
print("请输入合法的学号!")
|
|
|
|
|
|
def query_student():
|
|
name = input("请输入要查询的姓名:")
|
|
for index, student_dict in enumerate(student_list):
|
|
if name == student_dict["name"]:
|
|
student_id = index + 1
|
|
print("姓名:{},性别:{},电话:{}".format( student_dict["name"],
|
|
student_dict["sex"],student_dict["numbers"]))
|
|
break
|
|
else:
|
|
print("对不起,你查找的用户不存在")
|
|
|
|
|
|
def start():
|
|
while True:
|
|
show_menu()
|
|
menu_option = input("请输入您需要的功能序号:")
|
|
if menu_option == "1":
|
|
print("添加学员")
|
|
add_student()
|
|
elif menu_option == "2":
|
|
print("删除学员")
|
|
remove_student()
|
|
elif menu_option == "3":
|
|
print("修改学员信息")
|
|
modify_student()
|
|
elif menu_option == "4":
|
|
print("查询学员信息")
|
|
query_student()
|
|
elif menu_option == "5":
|
|
print("显示所有学员信息")
|
|
show_all_student()
|
|
elif menu_option == "6":
|
|
print("退出")
|
|
break
|
|
else:
|
|
print("输入格式错误")
|
|
break
|
|
start() |