Câu trả lời:
Code:
def sapxep(A):
for i in range(len(A)-1):
for j in range(len(A)-1-i):
if A[j] < A[j+1]: A[j],A[j+1] = A[j+1],A[j]
return A
with open('D:/input.txt','r',encoding = 'utf-8') as f:
A = [dong.strip() for dong in f]
f1 = open('D:/output.txt','w',encoding = 'utf-8')
B,C,D = [],[],[]
z = 3
for i in range(len(A)):
B.append(A[i].split(', '))
for i in range(len(B)):
C.append(B[i][1])
B[i][1] = float(B[i][1])
for i in range(len(C)):
C[i] = float(C[i])
sapxep(C)
while len(C) > 6:
C.remove(C[z])
for i in range(len(C)):
for j in range(len(B)):
if B[j][1] == C[i]: D.append(B[j][0])
for i in range(len(C)):
print(D[i],C[i],file = f1)
f.close()
f1.close()