all_students = [{'name': 'stu1', 'age': 19, 'score': 81, 'tel': '192222','Student_ID': '123456'}]
str_choice = '1、添加学生 ' \
'2、 查看学生' \
'3、 修改学生信息' \
'4、 删除学生' \
'5、 返回'
choice = 0
# 将choice初始化为0
while choice != 5:
# 当choice是5的时候,跳出循环
print(str_choice)
choice = int(input("输入数字选择以上选项:"))
if choice == 1:
all_students.append({'name': 1})
print('请输入需要添加的信息')
n = input('名字:')
all_students[-1]['name'] = n
n = input('年龄:')
all_students[-1]['age'] = n
n = input('成绩:')
all_students[-1]['score'] = n
n = input('电话:')
all_students[-1]['tel'] = n
n = input('学号:')
all_students[-1]['Student_ID'] = n
n = input('1、继续'
'2、返回')
# 此处判断是否继续,continue决定出去
if n == '1':
choice = 1
elif n == '2':
continue
elif choice == 2:
while choice != 4:
print('1、查找所有'
'2、按名字查询'
'3、按学号查询'
'4、返回')
choice = int(input("输入数字选择以上选项:"))
i = 0
# 后面用来获取循环次数,了解查找次数
if choice == 1:
for x in all_students:
print(x)
elif choice == 2:
n = input('请输入要查询的名字:')
for x in all_students:
if n == x['name']:
print(x)
continue
i += 1
if i == len(all_students):
print('查无此人')
elif choice == 3:
n = input('请输入要查询的学号:')
for x in all_students:
if n == x['Student_ID']:
print(x)
continue
i += 1
if i == len(all_students):
print('查无此人')
elif choice == 4:
continue
elif choice == 3:
n = 0
while n != '2':
n = input('请输入要修改的名字:')
# 此处顾名思义
for x in all_students:
if n == x['name']:
print('请输入需要变更的的信息')
n = input('名字:')
all_students[x]['name'] = n
n = input('年龄:')
all_students[x]['age'] = n
n = input('成绩:')
all_students[x]['score'] = n
n = input('电话:')
all_students[x]['tel'] = n
else:
print('查无此人')
n = input('1、继续'
'2、返回')
if n == '1':
choice = 3
continue
elif n == '2':
continue
elif choice == 4:
n = 0
while n != '2':
n = input('请输入要删除的名字:')
for x in all_students[:]:
if x['name'] == n:
all_students.remove(x)
else:
print('查无此人')
n = input('1、继续'
'2、返回')
网友评论