赞
踩
在本地电脑盘创建“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期末作业》
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。