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.
94 lines
2.5 KiB
94 lines
2.5 KiB
1 year ago
|
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('======回车键继续操作======')
|
||
|
|