我写了这段代码:
f = open('example.txt','r')
lines = f.readlines()
for i, line in enumerate(f):
if i < 3:
lines = ['LC '+line for line in lines]
with open('./example.txt', 'w') as f:
f.writelines(lines)
f.close()
elif i < 5:
lines = ['LB '+line for line in lines]
with open('./example.txt', 'w') as f:
f.writelines(lines)
f.close()
elif i > 6:
break
f.close()
我有一个 11 行的文件。我想从每一行开始写一些东西。3 第一行的单词不同,其他 2 的单词不同。你能帮我看看我做错了什么吗?