要求:
实现系统界面,功能界面,学号由迭代器或者生成器自动添加,实现添加学生、查询学生(按照姓名/学号查询)、修改学生(按照姓名或者学号修改学生的姓名/电话/年龄)、删除学生(按照学号/姓名删除)功能
ey_module模块
"""__author__ = 二扬"""
def sys_interface():
"""
打印学生管理系统界面
"""
print(("=" * 56).center(55, " "))
print("*" + "欢迎来到二扬的学生管理系统".center(42) + "*")
print("*" + " " * 54 + "*")
print("*" + "1. 添加学生".center(50) + "*")
print("*" + "2. 查询学生".center(50) + "*")
print("*" + "3. 修改学生".center(50) + "*")
print("*" + "4. 删除学生".center(50) + "*")
print("*" + "5. 退出系统".center(50) + "*")
print(("=" * 56).center(55, " "))
def add_function():
add_name = input("请输入学生姓名: ")
add_age = int(input("请输入学生年龄: "))
add_tel = int(input("请输入学生电话: "))
stu_information = {"name": add_name, "age": add_age, "tel": add_tel}
return stu_information
list_id = list(range(1, 101))
id_iter = iter(list_id)
def id_function():
add_id = next(id_iter)
return add_id
def add_interface():
print(("=" * 56).center(55, " "))
print("*" + "1. 继续添加学生".center(49) + "*")
print("*" + "2. 返回系统界面".center(49) + "*")
print(("=" * 56).center(55, " "))
def seek_stu():
print(("=" * 56).center(55, " "))
print("*" + "1. 通过姓名查询".center(49) + "*")
print("*" + "2. 通过学号查询".center(49) + "*")
print("*" + "3. 查询所有学生".center(49) + "*")
print("*" + "4. 返回系统界面".center(49) + "*")
print(("=" * 56).center(55, " "))
def change_stu():
print(("=" * 56).center(55, " "))
print("*" + "1. 修改学生姓名".center(49) + "*")
print("*" + "2. 修改学生年龄".center(49) + "*")
print("*" + "3. 修改学生电话".center(49) + "*")
print("*" + "4. 返回学生界面".center(49) + "*")
print(("=" * 56).center(55, " "))
def delete_stu():
print(("=" * 56).center(55, " "))
print("*" + "1. 通过姓名删除".center(49) + "*")
print("*" + "2. 通过学号删除".center(49) + "*")
print("*" + "3. 返回系统界面".center(49) + "*")
print(("=" * 56).center(55, " "))
学生管理系统
"""__author__ = 二扬"""
import ey_module
stu_list = []
key = 1
while key:
ey_module.sys_interface()
select = int(input("请输入您的选择: "))
while True:
if select == 1: # 增加学生功能
single_information = ey_module.add_function()
stu_id = str(ey_module.id_function()).rjust(4, "0")
single_information["id"] = ("python1807" + stu_id)
stu_list.append(single_information)
print("增加成功")
print(stu_list)
ey_module.add_interface()
value = int(input("请选择: "))
if value == 1:
pass
else:
break
elif select == 2: # 查找学生功能
ey_module.seek_stu()
select_num = int(input("请选择: "))
if select_num == 1: # 姓名查找
stu_name = input("请输入学生的姓名: ")
seek_list = []
for name_stu in stu_list:
if name_stu["name"] == stu_name:
seek_list.append(name_stu)
if seek_list:
print(seek_list)
else:
print("没有此学生,返回系统界面")
elif select_num == 2: # 学号查找
seek_id = input("请输入学生学号: ")
for id_seek in stu_list:
if id_seek["id"] == seek_id:
print(id_seek, "查询完毕,返回选择界面", sep="\n")
break
else:
print("没有此学生,返回选择界面")
elif select_num == 3: # 查找全部学生
print(stu_list, "查询完毕,返回选择界面", sep="\n")
else:
break
elif select == 3: # 修改学生功能
ey_module.change_stu()
select_num2 = int(input("请选择: "))
if select_num2 == 1: # 修改姓名
name_change = input("输入被修改的学生姓名: ")
change_name = input("输入被修改后的学生姓名: ")
change_list = []
dict_student = {}
for change_stu in stu_list:
if change_stu["name"] == name_change:
dict_student = change_stu
change_list.append(change_stu)
if len(change_list) == 1:
dict_student["name"] = change_name
print("修改成功,返回选择界面")
print(change_list)
elif len(change_list[:]) > 1:
print(change_list)
change_name_num = int(input("请问你要修改列表中第几个人的信息:"))
change_id = change_list[(change_name_num - 1)]["id"]
for id_ in stu_list:
if id_["id"] == change_id:
id_["name"] = change_name
print("修改成功, 返回选择界面")
print(id_)
break
else:
print("没有此学生,返回选择界面")
elif select_num2 == 2: # 修改年龄
name_change2 = input("请输入学生的姓名: ")
change_age = int(input("输入被修改后的学生年龄: "))
for change_stu2 in stu_list:
if change_stu2["name"] == name_change2:
change_stu2["age"] = change_age
print("修改成功,返回选择界面")
break
else:
print("没有此学生,返回选择界面")
elif select_num2 == 3: # 修改电话
name_change3 = input("请输入学生的姓名: ")
change_tel = int(input("输入被修改后的学生电话: "))
for change_stu3 in stu_list:
if change_stu3["name"] == name_change3:
change_stu3["tel"] = change_tel
print("修改成功,返回选择界面")
break
else:
print("没有此学生,返回选择界面")
else:
break
elif select == 4: # 删除学生功能
ey_module.delete_stu()
select_num3 = int(input("请选择: "))
if select_num3 == 1: # 通过姓名删除
delete_name = input("请输入被删除学生的姓名: ")
name_list = []
for name_delete in stu_list[:]:
if name_delete["name"] == delete_name:
name_list.append(name_delete)
if name_list:
print(name_list)
del_name = int(input("请输入你要删除列表中的第几个学生的信息: "))
stu_list.remove(name_list[(del_name - 1)])
print("删除成功,返回选择界面")
else:
print("没有此学生,返回选择界面")
elif select_num3 == 2: # 通过学号删除
delete_num = input("请输入被删除学生的学号: ")
for num_delete in stu_list[:]:
if num_delete["id"] == delete_num:
stu_list.remove(num_delete)
print("删除成功, 返回选择界面")
break
else:
print("没有此学生,返回选择界面")
else:
break
else:
print("谢谢使用学生管理系统")
key -= 1
break