在本地電腦盤創建“Python+【項目名稱】+【學號】+姓名”.doc文件。
操作過程截圖記錄到doc文件中。
答案:
f = open(r'C:\Users\86151\Desktop\test\test.txt',mode='r')
line = f.readlines()
print(sorted(line,key=lambda s:s[6: ],reverse=True))
nums = sorted(line,key=lambda s:s[6:],reverse=True)
with open(r'C:\Users\86151\Desktop\test\finally.txt',mode='w') as h:
for each in nums:
h.write(each)
我自己做的答案,太菜了,第四步就不能做出來。
f = open(r'C:\Users\86151\Desktop\test\test.txt',mode='r')
for line in f:
if (len(line.strip())==0):continue
print(line.strip())
f.close()
嘗試失敗:
f = open(r'C:\Users\86151\Desktop\test\test.txt',mode='r')
for line in f:
if (len(line.strip()) == 0): continue
L = [ ]
L = line.strip()
n = L[-2:]
L1 = []
L1.append(n)
# print(n + '\n')
print(L1)
f.close()
這裡是資料o
https://www.yuque.com/docs/share/661cba33-5ec0-43f2-b72a-69d1325f7061?#(密碼:gu69) 《Python期末作業》