1.通过键盘输入若干学生的学号,姓名,高数,英语,计算机5项数据,将这些学生成绩数据写入文件,文件名为“学生成绩表.txt”。
输入后对文件进行操作即可
id=input()
name=input()
math=input()
english=input()
computer=input()
with open('学生成绩表.txt', 'w') as f1:
f1.write('id:%s,name:%s,math:%s,english:%s,computer:%s' % (id, name, math, english, computer))
student_id = input('学号:')
name = input('姓名:')
math = input('高数:')
english = input('英语:')
computer = input('计算机:')
with open('a.txt', 'w') as f:
f.write('学号:%s\n姓名:%s\n高数:%s\n英语:%s\n计算机:%s\n'%(student_id,name,math,english,computer))
n = int(input("输入学生的人数n:"))
with open("data.txt","w", encoding='utf-8') as f:
for i in range(n):
s = input("第{}个学生的学号,姓名,高数,英语,计算机:".format(i+1))
f.write(s+'\n')