students = [
{"name": '小明', "num": '1811060301', "Class": "电子1802"},
{"name": '小天', "num": '1811060302', "Class": "电子1802"},
{"name": '小金刚', "num": '1811060303', "Class": "电子1802"},
{"name": '小红红红', "num": '1811060304', "Class": "电子1802"}
]
def add():
stu = {}
print("-------------------添加信息-------------------")
stu_name = input("请输入学生的名字:")
stu_num = input("请输入学生的学号:")
stu_class = input("请输入学生的班级:")
stu["name"] = stu_name
stu["num"] = stu_num
stu["Class"] = stu_class
print("添加的学生信息为:")
print("姓名:%-4s\t学号:%-8s\t班级:%s" % (stu_name, stu_num, stu_class))
students.append(stu)
print("-------------------添加完毕-------------------")
def delete():
print("-------------------删除信息-------------------")
num = input("请输入要删除学生的学号:")
for stu in students:
if num == stu['num']:
print("删除的学生信息为:")
print("姓名:%-4s\t学号:%-8s\t班级:%s" % (stu["name"], stu["num"], stu["Class"]))
students.remove(stu)
print("-------------------删除完毕-------------------")
return
print("-------------------查无此人-------------------")
def find():
print("-------------------查询信息-------------------")
num = input("请输入要查询学生的学号:")
for stu in students:
if num == stu['num']:
print("该学生信息为:")
print("姓名:%-4s\t学号:%-8s\t班级:%s" % (stu["name"], stu["num"], stu["Class"]))
stu_name = input("请输入学生的名字:")
stu_num = input("请输入学生的学号:")
stu_class = input("请输入学生的班级:")
students.remove(stu)
print("-------------------查询结束-------------------")
return
print("-------------------查无此人-------------------")
def modify():
print("-------------------修改信息-------------------")
stu1 = {}
num = input("请输入要要修改学生的学号:")
for stu in students:
if num == stu['num']:
print("该学生信息为:")
print("姓名:%-4s\t学号:%-8s\t班级:%s" % (stu["name"], stu["num"], stu["Class"]))
students.remove(stu)
print("-------------------重新录入-------------------")
stu1_name = input("请输入学生的名字:")
stu1_num = input("请输入学生的学号:")
stu1_class = input("请输入学生的班级:")
stu1["name"] = stu1_name
stu1["num"] = stu1_num
stu1["Class"] = stu1_class
students.append(stu1)
print("修改后的信息为:")
print("姓名:%-4s\t学号:%-8s\t班级:%s" % (stu1_name, stu1_num, stu1_class))
print("-------------------修改结束-------------------")
return
print("-------------------查无此人-------------------")
def show():
if students:
print("-------------------全部信息-------------------")
for stu in students:
print("姓名:%-4s\t学号:%-8s\t班级:%s" % (stu['name'], stu['num'], stu['Class']))
print("-------------------全部信息-------------------")
else:
print("-------------------暂无信息-------------------")
def interface():
print("-------------------进入系统-------------------")
while True:
op = int(input("请选择要进行的操作//添加(1)//删除(2)//查找(3)//修改(4)//显示全部(5)//退出(0)"))
if op == 0:
print('-'*5 + "退出系统" + '-'*5)
return
elif op == 1:
add()
elif op == 2:
delete()
elif op == 3:
find()
elif op == 4:
modify()
elif op == 5:
show()
interface()