studnet = []
file = open("学生信息", "r", encoding="utf-8")
for line in file: # 遍历的同时将字符串变为字典
studnet.append(eval(line))
while True:
need_del = input("输入要查找的学生id")
for i in studnet: # 遍历列表中的字典
if i['学号'] == need_del:
print(i)
break
else:
print('暂未查到该学生学号')
answer = input("继续查找?")
if answer.upper == "Y":
continue
else:
break
设想在输入y的时候回到while循环实际上会直接结束方法(也就是说会跳过循环)