我问下这里为什么要加 flag=False和flag=True,有谁能帮忙解释下吗?
def delete():
while True:
student_id=input('请输入要删除学生的ID:')
if student_id!='':
if os.path.exists(filename):
with open(filename,'r',encoding='utf-8')as file:
student_old=file.readlines()
else:
student_old=[]
flag=False
if student_old:
with open(filename,'w',encoding='utf-8')as wfile:
d={}
for item in student_old:
d=dict(eval(item))
if d['id']!=student_id:
wfile.write(str(d)+'\n')
else:
flag=True
if flag:
print(f'id为{student_id}的学生已被删除')
else:
print(f'没有找到ID为{student_id}的学生信息')
else:
print('无学生信息')
break