defget_stu():
f =open('d:\pythonwork 2021\students.txt')
student=[]for line in f:
line = line.replace('\t',' ')
s = line.replace('\n','')
student.append(s)
f.close()return student
defget_all():
students=get_stu()for i inrange(len(students)):for j inrange(len(students[i])):print(students[i][j],end='')print()defmenu():print('-'*20)print('学生姓名管理系统')print('1.添加学生信息')print('2.查找学生信息')print('3.修改学生信息')print('4.删除学生信息')print('5.显示所有学生信息')print('6.退出系统')print('-'*20)defadd():
students=get_stu()id=input('学号:')
name=input('姓名:')
gender=input('性别:')
age=input('年龄:')
class_=input('班级:')
major=input('专业:')
department=input('院系:')
phone=input('联系电话:')
students.append([id,name,gender,age,class_,major,department,phone])
f=open('d:\pythonwork 2021\students.txt','w')for i inrange(len(students)):
student=' '.join(students[i])+'\n'
f.write(student)
f.close()print('\033[4;33m添加成功!\033[0m')deffind():
f =open('d:\pythonwork 2021\students.txt')
student =[]for line in f:
line = line.replace('\t',' ')
s = line.replace('\n','')
ss = s.split(' ')
student.append(ss)
f.close()whileTrue:print('1.姓名查询')print('2.学号查询')
choose =input('请选择查询方式:')if choose =='1':
found =False
name =input('请输入要查询的学生的姓名:')for st in student:if(st[1]==name):
found=True
count=0for i inrange(len(st)):print(st[i],end=' ')
count+=1