1 stu_list = [] 2 def func1(): 3 num_srt = input('请输入新生学号:') 4 num = int(num_srt) 5 name = input('请输入新生姓名:') 6 age = input('请输入新生年龄:') 7 stu = { 'stu_num':num,'stu_name':name,'stu_age':age} 8 stu_list.append(stu) 9 print('添加成功')10 11 def func2():12 num_str = input('请输入学生学号:')13 num = int(num_str)14 is_exists = True15 for stu in stu_list:16 num1 = stu.get('stu_num')17 if num1 == num:18 stu_list.remove(stu)19 print('删除成功!')20 is_exists = False21 if is_exists:22 print('你输入的学号不存在!')23 24 def func3():25 num_str = input('请输入要修改信息学生的学号:')26 num = int(num_str)27 is_exists = True28 for stu in stu_list:29 num1 = stu.get('stu_num')30 if num1 == num:31 print('学号是:',stu.get('stu_num'),'姓名是:',stu.get('stu_name'),'年龄是:',stu.get('stu_age'))32 new_age = input('请输入新的年龄:')33 stu['stu_age']= int(new_age)34 print('修改成功!')35 is_exists = False36 if is_exists:37 print('你输入的学号不存在!')38 39 def func4():40 num = int(input('请输入学号:'))41 is_exists = True42 for stu in stu_list:43 num1 = stu.get('stu_num')44 if num1 == num:45 print('学号是:',stu.get('stu_num'),'姓名是:',stu.get('stu_name'),'年龄是:',stu.get('stu_age'))46 is_exists = False47 if is_exists:48 print('学号输入有误,请查证后再输入!')49 50 def main():51 while True:52 choice = input('A、添加学生 B、根据学号删除学生 C、修改信息 D、查询 E、退出')53 if choice == 'A' or choice == 'a':54 func1()55 elif choice == 'B' or choice == 'b':56 func2()57 elif choice == 'C' or choice == 'c':58 func3()59 elif choice == 'D' or choice == 'd':60 func4()61 elif choice == 'E' or choice == 'e':62 break63 print('当前班级学生信息:')64 for stu in stu_list:65 print('学号是:',stu.get('stu_num'),'姓名是:',stu.get('stu_name'),'年龄是:',stu.get('stu_age'))66 print('****'*10)67 68 main()