import copy
name_students_information = {}
number_students_information = {}
personal_information = {}
personal_information2 = {}
while True:
print("===================================================================")
print("✿✿欢迎yuting:\n")
print("\t❤ 1. 添加学生\n\t❤ 2. 查看学生\n\t❤ 3. 修改学生信息\n\t❤ 4. 删除学生\n\t❤ 5. 返回")
print("===================================================================")
choice1 = input("请选择(1-5):")
# 数据关系 一个列表保存多个学生的个人信息,每个学生的个人信息保存学号,年龄,姓名等内容.
# 创建一个列表,列表里面包含许多个字典(个人信息),查找信息时,先遍历列表定位,
# 添加学生
if choice1 == '1':
while True:
number = input("请输入学号:")
personal_information.update({'学号': number})
name = input("请输入学生姓名:")
personal_information.update({'姓名': name})
age = input("请输入学生年龄:")
personal_information.update({'年龄': age})
tel = input("请输入学生电话:")
personal_information.update({'电话': tel})
name_students_information.update({name: copy.deepcopy(personal_information)})
number_students_information.update({number: name_students_information[name]})
personal_information.clear()
print("添加成功!\n1.继续\n2.返回")
value1 = input("请选择(1-2)")
if value1 == '1':
continue
elif value1 == '2':
break
# 查看学生
elif choice1 == '2':
while True:
print("1.查看所有学生\n2.按姓名查找\n3.按学号查找\n4.返回")
choice2 = input("请选择(1-4)")
if choice2 == '1': # 1.查看所有学生
for name1 in name_students_information:
for key in name_students_information[name1]:
print(key, ' ', name_students_information[name1][key], end=' ')
print('\n')
elif choice2 == '2': # 2. 按姓名查找
name2 = input("请输入姓名:")
if name_students_information.get(name2) == None:
print("没有这名学生!")
else:
for key in name_students_information[name2]:
print(key, ' ', name_students_information[name2][key], end=' ')
print('\n')
elif choice2 == '3': # 3.按学号查找
number1 = input("请输入学号:")
if number_students_information.get(number1) == None:
print("没有这名学生!")
else:
for key in number_students_information[number1]:
print(key, ' ', number_students_information[number1][key], end=' ')
print('\n')
elif choice2 == '4':
break
else:
print("请重新输入!")
# 修改学生信息
elif choice1 == '3':
while True:
name3 = input("请输入要修改的学生的名字:")
if name_students_information.get(name3) == None:
print("没有找到该学生,请重新输入!")
break
else:
number = input("请输入新的学号:")
personal_information.update({'学号': number})
name = input("请输入学生新的姓名:")
personal_information.update({'姓名': name})
age = input("请输入学生新的年龄:")
personal_information.update({'年龄': age})
tel = input("请输入学生新的电话:")
personal_information.update({'电话': tel})
del name_students_information[name]
name_students_information.update({name: copy.deepcopy(personal_information)})
number_students_information.update({number: name_students_information[name]})
personal_information.clear()
print("修改成功!")
choice3 = input("1. 继续\n2. 返回")
if choice3 == '1':
continue
elif choice3 == '2':
break
# 删除学生
elif choice1 == '4':
while True:
name3 = input("请输入要删除的学生名")
if name_students_information.get(name3) == None:
print("没有找到该学生,请重新输入!")
break
else:
choice4 = input("确定要删除吗? 1. 确认删除\n2. 取消")
if choice4 == '1':
del name_students_information[name3]
elif choice4 == '2':
continue
else:
print("请重新输入!")
# 返回
elif choice1 == '5':
break
else:
print("请重新输入!")
网友评论