parent
85dee27daf
commit
94a85bc0f7
@ -0,0 +1,105 @@
|
||||
stu_list=[]
|
||||
#系统菜单
|
||||
def show_menu():
|
||||
print('1.添加学生')
|
||||
print('2.删除学生')
|
||||
print('3.修改学生信息')
|
||||
print('4.查询单个学生信息')
|
||||
print('5.查询所有学生信息')
|
||||
print('6.保存学生信息')
|
||||
print('7.退出系统')
|
||||
|
||||
#添加学生
|
||||
def insert_student():
|
||||
name=input('姓名')
|
||||
#-----------
|
||||
for i in stu_list:
|
||||
if i['name'] == name:
|
||||
print('学生信息已存在')
|
||||
return
|
||||
age=input('性别')
|
||||
gender=input('手机号')
|
||||
#将学生信息添加在字典
|
||||
stu_dict={'name':name,'age':int(age),'gender':gender}
|
||||
#将字典添加在列表
|
||||
stu_list.append(stu_dict)
|
||||
print('==========学生信息添加成功==========')
|
||||
|
||||
|
||||
#查找所有学生信息
|
||||
def show_all_student():
|
||||
if len(stu_list)>0:
|
||||
for i in stu_list:
|
||||
print(f'名字:{i["name"]},性别:{i["age"]},手机号:{i["gender"]}')
|
||||
else:
|
||||
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['age']=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["age"]},手机号:{i["gender"]}')
|
||||
return
|
||||
else:
|
||||
print('该学生信息不存在,无法查询-------------------')
|
||||
|
||||
def save():
|
||||
#打开文件
|
||||
f=open('stydent.txt','w',encoding='utf-8')
|
||||
f.write(str(stu_list))
|
||||
f.close()
|
||||
|
||||
|
||||
def main():
|
||||
while True:
|
||||
show_menu()
|
||||
n=int(input('请选择要执行的编号:'))
|
||||
if n==1:
|
||||
insert_student()
|
||||
elif n==2:
|
||||
remove_student()
|
||||
elif n==3:
|
||||
modify_student()
|
||||
elif n==4:
|
||||
search_student()
|
||||
elif n==5:
|
||||
show_all_student()
|
||||
elif n==6:
|
||||
save()
|
||||
elif n==7:
|
||||
、 print('欢迎下次使用本系统..........')
|
||||
save()
|
||||
break
|
||||
else:
|
||||
print('您输入有误,请再次输入')
|
||||
continue
|
||||
input('......回车键继续操作.....')
|
||||
|
||||
|
||||
main()
|
Loading…
Reference in new issue