num = 0
student_name = {}
student_name1 = {}
student_number = {}
student_name_number = {}
student_number_name = {}
while num == 0:
print(' 1. 添加学生')
print(' 2. 查看学生')
print(' 3. 修改学生信息')
print(' 4. 删除学生')
print(' 5. 返回')
num = int(input('请选择(1-5):'))
while num == 1:
name_value = input('请输入姓名:')
age_value = input('请输入年龄:')
phone_value = input('请输入电话:')
stu_number = input('请输入学号:')
student_name_number[name_value] = stu_number
student_number_name[stu_number] = name_value
student_name1['姓名'] = name_value
student_name1['年龄'] = age_value
student_name1['电话'] = phone_value
student_name1['学号'] = stu_number
student_name[name_value] = student_name1
student_number[stu_number] = student_name1
print('添加成功!')
print('1.继续')
print('2.返回')
num = int(input('请选择(1-2):'))
if num == 2:
num = 0
break
while num == 2:
print(' 1. 查看所有学生')
print(' 2. 按姓名查找')
print(' 3. 按学号查找')
print(' 4. 返回')
num = int(input('请选择(1-4):'))
if num == 1:
for key in student_name:
print(key, student_name[key])
print('查找成功')
num = 2
continue
if num == 2:
name_value = input('请输入姓名:')
if name_value in student_name:
print(student_name[name_value])
print('查找成功')
if num == 3:
stu_number = input('请输入学号:')
if stu_number in student_number:
print(student_number[stu_number])
print('查找成功')
num = 2
if num == 4:
num = 0
break
while num == 3:
name_value = input('请输入姓名:')
age_value = input('请输入年龄:')
phone_value = input('请输入电话:')
stu_number = input('请输入学号:')
if name_value in student_name_number and student_name_number[name_value] != stu_number:
print('名字与学号不对应!')
num = 0
continue
if stu_number in student_number_name and student_number_name[stu_number] == name_value:
print('学号与名字不对应!')
num = 0
continue
student_name1['姓名'] = name_value
student_name1['年龄'] = age_value
student_name1['电话'] = phone_value
student_name1['学号'] = stu_number
student_name[name_value] = student_name1
student_number[stu_number] = student_name1
print('修改成功!')
print('1.继续')
print('2.返回')
num = int(input('请选择(1-2):'))
if num == 1:
num = 3
if num == 2:
num = 0
break
while num == 4:
name_value = input('请输入姓名:')
stu_number = input('请输入学号:')
del student_name[name_value]
del student_number[stu_number]
print('删除成功!')
num = 0
if num == 5:
break
print('退出系统!')
运行: