class Student:
def add(self,**kwargs):
f = open('./2.text','a',encoding='utf-8')
f.write(str(kwargs)+'\n')
f.close()
def check_all(self):
f =open('./2.text','r',encoding='utf-8')
result5 =f.read()
f.close()
return result5
def check(self,num):
all_stu_ifo = self.check_all()
result3 =all_stu_ifo.split('\n')
del result3[-1]
for i in result3:
dic_inf =eval(i)
# print(dic_inf)
if num ==dic_inf['学号']:
print(dic_inf)
def write(self,dict):
f = open('./2.text', 'w', encoding='utf-8')
f.write(str(dict)+'\n')
f.close()
def edit(self,**kwargs):
sut_all_inf = self.check_all()
result5 = sut_all_inf.split('\n')
del result5[-1]
w = 1
# print(result5)
for i in result5:
dict_inf = eval(i)
if dict_inf['学号']==kwargs['学号']:
dict_inf['姓名'] = kwargs['姓名']
dict_inf['年龄'] = kwargs['年龄']
if w:
self.write(dict_inf)
else:
self.add(学号 = dict_inf['学号'],姓名 = dict_inf['姓名'],年龄 = dict_inf['年龄'])
w = 0
def dele(self,**kwargs):
sut_all_inf = self.check_all()
result5 = sut_all_inf.split('\n')
del result5[-1]
e = 1
for i in result5:
dict_inf = eval(i)
# print(dict_inf)
if dict_inf['学号']!=kwargs['学号']:
if e:
self.write(dict_inf)
else:
self.add(学号=dict_inf['学号'], 姓名=dict_inf['姓名'], 年龄=dict_inf['年龄'])
e = 0
user = Student()
str1 = '欢迎来到学生管理系统'
print(str1.center(50,'='))
while True:
print('请输入你的选择')
checked = input('添加(A),查询(C),编辑(E),删除(D),退出(Q):')
checked = checked.lower()
if checked == 'a':
print('添加操作')
result = input('请输入你的【学号 姓名 年龄】中间以一个空格隔开')
result1 = result.split(' ')
user.add(学号 = result1[0],姓名 = result1[1],年龄 = result1[2])
result9 = user.check_all()
print(result9)
print('添加成功')
elif checked == 'c':
print('查询操作')
result2 = input('查询所有人的信息请输入1,查询个人信息请输入学号:')
if result2 == '1':
all_stu_ifo = user.check_all()
print(all_stu_ifo)
else:
all_stu_pen = user.check(result2)
elif checked == "e":
print('编辑操作')
result4 = input('输入你要更改的信息,学号不允许更改【学号 姓名 年龄】中间以一个空格隔开:')
result3 = result4.split(' ')
user.edit(学号 = result3[0],姓名 = result3[1],年龄 = result3[2])
result7 = user.check_all()
print(result7)
elif checked =='d':
print('删除操作')
result5 = input('请输入你要删除的个人信息,输入【学号 姓名 年龄】')
result6 = result5.split(' ')
user.dele(学号 = result6[0],姓名 = result6[1],年龄 = result6[2])
result8 = user.check_all()
print(result8)
else:
print('退出操作')
break
简单的学生系统
最新推荐文章于 2022-11-17 21:18:16 发布