制作一个简单的学生信息管理系统
"""
__author__ = 'rz'
__Time__ = 2018/8/28 0028 下午 4:20
"""
student_list = [
{'id':2018001,'name':'admin','age':20,'phone':'10086'},
{'id':2018002,'name':'Lucian','age':20,'phone':'10010'},
{'id':2018003,'name':'lax','age':20,'phone':'10000'}
]
def menu():
#print(student_list)
print('\n***********************************')
print('XXX管理系统'.center(17,' '))
print('1.添加学生信息'.center(15,' '))
print('2.修改学生信息'.center(15, ' '))
print('3.查看学生信息'.center(15, ' '))
print('4.删除学生信息'.center(15, ' '))
print('0.退出学生系统'.center(15, ' '))
print('***********************************\n')
choose = input('输入功能选项:')
if choose == '1':
add_student()
elif choose == '2':
edit_student()
elif choose == '3':
query_student()
elif choose == '4':
delete_student()
elif choose == '0':
exit()
else:
print('选项有误,请重新输入')
menu()
def add_student():
print('\n')
print('添加学生'.center(15,' '))
name = input('输入学生的姓名:')
age = input('输入学生的年龄:')
phone = input('输入学生的电话:')
stu_len = len(student_list)
student_id = student_list[stu_len-1]['id'] + 1
student = {'id':student_id,'name':name,'age':age,'phone':phone}
student_list.append(student)
if stu_len < len(student_list):
print('添加学生成功.')
else:
print('添加学生失败,请联系管理员.')
print('\n')
print('选择操作选项'.center(15, ' '))
print('1.继续添加学生'.center(15, ' '))
print('0.返回功能界面'.center(15, ' '))
while True:
choose = input('输入(按0返回/按1继续添加):')
if choose == '0':
menu()
elif choose == '1':
add_student()
else:
print('输入有误,请重新输入。')
def edit_student():
print('\n')
print('修改学生'.center(15, ' '))
stu_id = int(input('输入需要修改的学生id:'))
for n in range(len(student_list)):
if student_list[n]['id'] == stu_id:
print('学生信息:',student_list[n])
name = input('输入修改后学生的姓名:')
age = input('输入修改后学生的年龄:')
phone = input('输入修改后学生的电话:')
student_list[n]['name'] = name
student_list[n]['age'] = age
student_list[n]['phone'] = phone
print('修改成功,核实学生信息--',student_list[n])
break
else:
print('没有此名学生,请重新选择。')
edit_student()
print('\n')
print('选择操作选项'.center(15, ' '))
print('1.继续修改学生'.center(15, ' '))
print('0.返回功能界面'.center(15, ' '))
while True:
choose = input('输入(按0返回/按1继续修改):')
if choose == '0':
menu()
elif choose == '1':
edit_student()
else:
print('输入有误,请重新输入。')
def query_student():
print('\n')
print('学生信息查询'.center(15, ' '))
print('1.按照姓名查询'.center(15, ' '))
print('2.按照年龄查询'.center(15, ' '))
print('3.全部查询'.center(15, ' '))
while True:
choose = input('输入选项:')
if choose == '1':
query_name()
elif choose == '2':
query_age()
elif choose == '3':
query_all()
else:
print('输入有误,请重新输入。')
def query_name():
name = input('输入学生名字(粗略查找):')
count = 0
for n in range(len(student_list)):
if name in student_list[n]['name']:
print(student_list[n])
count += 1
print('共找到符合要求的学生 %d 名' % count)
print('\n')
print('选择操作选项'.center(15, ' '))
print('1.继续查找学生'.center(15, ' '))
print('0.返回功能界面'.center(15, ' '))
while True:
choose = input('输入(按0返回/按1继续查找):')
if choose == '0':
menu()
elif choose == '1':
query_student()
else:
print('输入有误,请重新输入。')
def query_age():
age = input('输入学生年龄(粗略查找):')
count = 0
for n in range(len(student_list)):
if age == str(student_list[n]['age']):
print(student_list[n])
count += 1
print('共找到符合要求的学生 %d 名' % count)
print('\n')
print('选择操作选项'.center(15, ' '))
print('1.继续查找学生'.center(15, ' '))
print('0.返回功能界面'.center(15, ' '))
while True:
choose = input('输入(按0返回/按1继续查找):')
if choose == '0':
menu()
elif choose == '1':
query_student()
else:
print('输入有误,请重新输入。')
def query_all():
print('\n')
for n in range(len(student_list)):
print(student_list[n])
print('\n')
print('选择操作选项'.center(15, ' '))
print('1.继续查找学生'.center(15, ' '))
print('0.返回功能界面'.center(15, ' '))
while True:
choose = input('输入(按0返回/按1继续查找):')
if choose == '0':
menu()
elif choose == '1':
query_student()
else:
print('输入有误,请重新输入。')
def delete_student():
print('\n')
print('删除学生'.center(15, ' '))
stu_id = int(input('输入需要删除的学生id:'))
for n in range(len(student_list)):
if student_list[n]['id'] == stu_id:
print('学生信息:',student_list[n])
while True:
print('\n确认删除吗? y确认/n取消')
choose = input().upper()
if choose == 'Y':
del student_list[n]
print('id %s 的学生删除成功' % stu_id)
break
elif choose == 'N':
break
else:
print('输入有误,请重新输入.')
print('\n')
print('选择操作选项'.center(15, ' '))
print('1.继续删除学生'.center(15, ' '))
print('0.返回功能界面'.center(15, ' '))
while True:
choose = input('输入(按0返回/按1继续删除):')
if choose == '0':
menu()
elif choose == '1':
delete_student()
else:
print('输入有误,请重新输入。')
if __name__ == '__main__':
menu()