defdel_student(): global student_info del_num = input("请输入要删除学生的学号:") for i in student_info: if i['num'] == del_num: student_info.remove(i) print("删除成功!") else: continue
5,修改学生信息update_student_info()
跟之前的删除学生的逻辑基本差不多,这里就不做过多赘述了,上代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
defupdate_student_info(): global student_info update_num = input('请输入要修改学生信息的编号:') for i in student_info: try: if i['num'] == update_num: new_num = input('请输入新的学生编号:') new_name = input('请输入新的学生名字:') new_tel = input('请输入新的学生电话:') i['name'] = new_name i['num'] = new_num i['tel'] = new_tel print("修改完毕") else: continue except Exception as e: print(e)
6,查询学生信息find_student_info()
1 2 3 4 5 6 7 8 9
deffind_student_info(): global student_info search_num = input('请输入要查询学生的编号:') for i in student_info: if i['num'] == search_num: print(f'此学生的学号为{i["num"]}, 姓名为{i["name"]}, 电话为{i["tel"]}') else: continue
7,显示所有学生信息show_all()
1 2 3 4 5
defshow_all(): global student_info print("姓名\t\t学号\t\t电话\t\t") for i in student_info: print(f"{i['name']}\t\t{i['num']}\t\t{i['tel']}")