grade.txt中文件中存储了学生的学号,姓名,Python的成绩,请根据Python成绩填写‘是否及格’。如果Python成绩大于等于60 则填写‘及格’,否则填写‘不及格’。
默认学号,姓名,Python的成绩以空格隔开,然后结果保存在文件result.txt里:
with open('grade.txt','r') as f:
p=f.readlines()
p = [i.strip().split() for i in p]
for i in p:
if int(i[2])>=60:
i.append('及格')
else:
i.append('不及格')
with open('result.txt','w') as f:
for i in p:
f.write(' '.join(i)+'\n')