all_students = []
while True:
print('欢迎进入学生管理系统')
print(' ')
print('1.添加学生')
print(' ')
print('2.查看学生')
print(' ')
print('3.修改学生信息')
print(' ')
print('4.删除学生')
print(' ')
print('5.退出')
choice = input('请选择(1-5):')
while int(choice) not in range(1, 6):
choice = input('您的输入有误,请重新输入!(1-5):')
if int(choice) == 1:
while True:
name = input('请输入学生姓名:')
age = input('请输入学生的年龄:')
tel = input('请输入学生的电话:')
print('添加成功')
new_student = {'姓名:': name, '年龄:': age, '电话:': tel}
all_students.append(new_student)
add_choice = int(input('1.继续\n2.返回'))
while add_choice not in range(1, 3):
add_choice = input('您的输入有误,请重新输入!(1-2):')
if add_choice == 2:
break
elif int(choice) == 2:
while True:
print('1.查看所有学生')
print('2.按姓名查找')
print('3.按学号查找')
print('4.返回')
find_choice = input('请选择(1-4)')
while int(find_choice) not in range(1, 5):
find_choice = input('您的输入有误,请重新输入!(1-4):')
if int(find_choice) == 1:
print(all_students)
elif int(find_choice) == 2:
while True:
find_name = input('请输入查找学生的姓名:')
for stu in all_students:
if find_name == stu['姓名:']:
print(stu)
break
else:
print('您所查找的学生不存在')
print('是否继续查找?1.继续\n2.返回')
find_choice_2 = int(input('请输入(1-2)'))
while find_choice_2 not in range(1, 3):
find_choice_2 = int(input('您的输入有误,请重新输入!(1-2):'))
if find_choice_2 == 2:
break
elif int(find_choice) == 3:
print('学号还没')
elif int(find_choice) == 4:
break
elif int(choice) == 3:
while True:
revise_stu = input('请输入想修改的学生姓名:')
for stu in all_students:
if stu['姓名:'] == revise_stu:
print(stu)
print('请选择您想修改的项目:')
print('1.姓名\n2.年龄\n3.电话\n4.返回')
revise_choice = int(input('请选择;(1-4)'))
while revise_choice not in range(1, 5):
revise_choice = int(input('您的输入有误,请重新输入!(1-4):'))
if revise_choice == 1:
new_name = input('请输入新姓名:')
stu['姓名:'] = new_name
print('修改成功!')
print(stu)
if revise_choice == 2:
new_age = input('请输入新年龄:')
stu['年龄:'] = new_age
print('修改成功!')
print(stu)
if revise_choice == 3:
new_tel = input('请输入新电话:')
stu['电话:'] = new_tel
print('修改成功!')
print(stu)
if revise_choice == 4:
break
else:
print('没有查到此学生')
print('是否继续?1.继续\n2.返回')
revise_choice_2 = int(input('请输入(1-2)'))
while revise_choice_2 not in range(1, 3):
revise_choice_2 = int(input('您的输入有误,请重新输入!(1-2):'))
if revise_choice_2 == 2:
break
elif int(choice) == 4:
while True:
remove_stu = input('请输入想要删除学生的姓名:')
for stu in all_students:
if stu['姓名:'] == remove_stu:
all_students.remove(stu)
print('删除成功!')
else:
print('没有查到此学生')
print('是否继续?1.继续\n2.返回')
remove_choice = int(input('请输入(1-2)'))
while remove_choice not in range(1, 3):
remove_choice = int(input('您的输入有误,请重新输入!(1-2):'))
if remove_choice == 2:
break
elif int(choice) == 5:
break
网友评论