Professional Documents
Culture Documents
Bai Tap Chuong 6
Bai Tap Chuong 6
sample.txt
sample1.txt
time,id,score
2022-05-16,10,9
2022-05-16,5,10
2022-05-17,3,9
2022-05-18,5,10
2022-05-19,10,8
2022-05-19,5,9
2022-05-20,3,10
2022-05-21,2,9
2022-05-22,10,10
a. Tạo thêm một cột là số thứ tự nằm bên trái cột “time", số thứ tự bắt
đầu từ 1, ghi ra một tệp mới.
c=0
stt = []
t = []
ids = []
scores =[]
test.txt
0
1
2
3
4
5
6
7
8
9
10
11
12
13
i=0
with open(‘test.txt’, ‘r’) as fi:
for line in fi:
if i%2==0:
print(line.rstrip())
i+=1
8. Viết chương trình ghi một danh sách dưới đây ra một tập tin tên bất kỳ.
color = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
color = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
with open('colors', 'w') as f:
for color in colors:
f.write(f"{color}\n")