import copy
num = 0
list1=[]
dict2 = {'学号':'stu'}
while 1:
print('1.添加学生\n2.查看学生\n3.修改学生信息\n4.删除学生\n5.返回')
y = int(input('请选择1-5:'))
if y == 1:
while 1:
num += 1
str2 = 'stu'+ str(num).rjust(3, '0')
dict2['学号'] = str2
x = input('姓名')
dict2.update({'姓名':x})
x = int(input('age'))
dict2.update({'age':x})
x = int(input('del'))
dict2.update({'del': x})
dict3=copy.deepcopy(dict2)
list1.append(dict3)
print('添加成功')
z=int(input('1.继续\n2.返回\n请输入:'))
if z==2:
break
elif y==2:
print('1.查看所有学生\n2.按姓名查找\n3.按学号查找\n4.返回')
a = int(input('请输入:'))
if a==1:
for dict2 in list1:
a1 = dict2.get('学号')
a2 = dict2.get('姓名')
a3 = dict2.get('age')
a4 = dict2.get('del')
print('学号:%s 姓名:%s age:%d del:%d' % (a1,a2,a3,a4))
elif a==2:
b = input('请输入学生姓名:')
print(b)
for dict2 in list1:
if dict2.get('姓名') == b:
a1 = dict2.get('学号')
a2 = dict2.get('姓名')
a3 = dict2.get('age')
a4 = dict2.get('del')
print('学号:%s 姓名:%s age:%d del:%d' % (a1, a2, a3, a4))
else:
print('没有此学生')
elif a==3:
c = input('请输入学生学号:')
for dict2 in list1:
if dict2.get('学号') == c:
a1 = dict2.get('学号')
a2 = dict2.get('姓名')
a3 = dict2.get('age')
a4 = dict2.get('del')
print('学号:%s 姓名:%s age:%d del:%d' % (a1, a2, a3, a4))
else:
print('没有此学生')
elif y==3:
for dict2 in list1:
a1 = dict2.get('学号')
a2 = dict2.get('姓名')
a3 = dict2.get('age')
a4 = dict2.get('del')
print('学号:%s 姓名:%s age:%d del:%d' % (a1, a2, a3, a4))
print('是否需要修改')
d = int(input('1.要\n2.不\n请输入:'))
if d==1:
print('请修改')
e=input('key=:')
f = input('value=:')
dict2[e] = f
a1 = dict2.get('学号')
a2 = dict2.get('姓名')
a3 = dict2.get('age')
a4 = dict2.get('del')
print('学号:%s 姓名:%s age:%d del:%d' % (a1, a2, a3, a4))
break
elif y==4:
for dict2 in list1:
a1 = dict2.get('学号')
a2 = dict2.get('姓名')
a3 = dict2.get('age')
a4 = dict2.get('del')
print('学号:%s 姓名:%s age:%d del:%d' % (a1, a2, a3, a4))
print('是否需要删除')
d = int(input('1.要\n2.不\n请输入:'))
if d == 1:
list1.remove(dict2)
break
网友评论