From b2f5c32a53e02a1c0cf6f459b3230a7502613117 Mon Sep 17 00:00:00 2001 From: pwihf5mjr <3200695141@qq.com> Date: Tue, 21 Nov 2023 15:06:43 +0800 Subject: [PATCH] ADD file via upload --- 12345678.txt | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 12345678.txt diff --git a/12345678.txt b/12345678.txt new file mode 100644 index 0000000..5e32866 --- /dev/null +++ b/12345678.txt @@ -0,0 +1,93 @@ +stu_list=[] +def menu(): + print("1.添加学生") + print("2.删除学生") + print("3.修改学生信息") + print("4.查询学生信息") + print("5.显示学生信息") + print("6.保存学生信息") + print("7.退出系统") + +def add_student():#添加学生信息 + name = input('请输入学生姓名:') + # ----------- + for i in stu_list: + if i['name'] == name: + print('学生信息已存在') + return + gender= input("请输入学生性别:") + phone=input("请输入学生电话:")#加入信息 + stu_dict= { 'name': name, 'gender': gender,'phone':phone} + stu_list.append(stu_dict) + print() + + +def remove_student():#删除学生信息 + name=input('请输入要删除学生姓名:') + for i in stu_list: + if i['name'] == name: + stu_list.remove(i) + print('学生信息删除成功') + return + else: + print('该学生信息不存在,无法删除') + +def modify_student(): + name=input('请输入要修改学生姓名:') + for i in stu_list: + if i['name'] == name: + i['gender']=input('请输入修改性别:') + i['phone']=int(input('请输入电话:')) + print('修改成功') + return + else: + print('该学生信息不存在,无法修改') + +def search_student(): + name=input('请输入学生姓名:') + for i in stu_list: + if i['name'] == name: + print(f'姓名:{i["name"]},性别:{i["gender"]},电话:{i["phone"]}') + return + else: + print('该学生信息不存在,无法查询-------------------') + +def show_student(): + if len(stu_list)>0: + for i in stu_list: + print(f'名字:{i["name"]},性别:{i["gender"]},电话:{i["phone"]}') + else: + print("没有此学生信息") + +def save(): + #打开文件 + f=open('stydent.txt','w',encoding='utf-8') + f.write(str(stu_list)) + f.close() + print("保存成功") + + +while True: + + num=eval(input("请输入序号:")) + if num==1: + add_student() + elif num==2: + remove_student() + elif num==3: + modify_student() + elif num==4: + search_student() + elif num==5: + show_student() + elif num==6: + save() + elif num==7: + print('退出系统,欢迎下次使用') + save() + break + else: + print("输入有误,请再次输入") + continue + input('======回车键继续操作======') +