student_id = []
student_name = []
student_age = []
student_class = []
student_count = 0
while True:
result1 = 'y'
r = 'y'
title_sys = '学生信息管理系统'
title_fun1 = '1 添加学生'
title_fun2 = '2 修改信息'
title_fun3 = '3 查看学生'
title_fun4 = '4 立即退出'
print(title_sys.center(50),end='\n\n')
print(title_fun1.center(50))
print(title_fun2.center(50))
print(title_fun3.center(50))
print(title_fun4.center(50))
print('本系统学生编号自动生成,根据登记次序为‘2018_xxx’')
print('='*50)
try:
order = int(input('请选择要进行的操作:'))
if order == 1:
while result1 == 'y':
s_n = input('输入学生姓名:')
s_a = input('输入学生年龄:')
s_c = input('请为该生分配其班级:')
student_count += 1
student_name.append(s_n)
student_age.append(s_a)
student_class.append(s_c)
str_id = '2018_'+str(student_count).rjust(3,'0')
student_id.append(str_id)
print('添加成功')
result1 = input('是否继续添加y/n:')
print('-'*50)
elif order == 2:
while r == 'y':
if len(student_id) != 0:
result2 = 'y'
flag = 1
print('可用于修改的学生id:',student_id)
updata_id = input('请输入要修改学生的id:')
index = student_id.index(updata_id)
while result2 == 'y':
m1 = '请选择修改项'
m2 = '1.学生姓名'
m3 = '2.学生年龄'
m4 = '3.分配班级'
m5 = '4.直接删除'
print(m1.center(50),end='\n\n')
print(m2.center(50))
print(m3.center(50))
print(m4.center(50))
print(m5.center(50))
print('-'*50)
updata_order = int(input('您的选择是:'))
if updata_order == 1:
student_name[index] = input('请输入新名字:')
print('修改完毕')
elif updata_order == 2:
student_age[index] = input('请输入新年龄:')
print('修改完毕')
elif updata_order == 3:
student_class[index] = input('请输入新班级:')
print('修改完毕')
else:
flag = 0
del student_name[index]
del student_age[index]
del student_class[index]
del student_id[index]
print('删除完毕')
if flag:
result2 = input('是否继续修改该学生的信息 y/n:')
else:
result2 = 'n'
r = input('是否继续修改学生信息 y/n:')
else:
print('无可修改项')
break
print('-'*50)
elif order == 3:
try:
for i in range(student_count):
print('学生id:%s 学生姓名:%s 学生年龄:%s 学生班级:%s'%(student_id[i],student_name[i],student_age[i],student_class[i]))
except:
print('无记录')
print('-'*50)
else:
break
except:
continue
结果如下(部分):