实验六
2022/5/24 23:20:53
本文主要是介绍实验六,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
def is_valid(m): if len(m)==18 and m.isdigit(): return 'True' elif len(m)==18 and m[-1]=='X': return 'True' else: return 'False' with open('D:/实验六数据文件data3_id.txt','r',encoding = 'utf-8') as f: data = f.readlines() list = [] for i in data: data_ = i.strip('\n') if is_valid(data_[3:]) == 'True': list.append(data_) list.sort(key=lambda x: x[9:13]) for m in list: print('{},{}-{}-{}'.format(m[:2],m[9:13],m[13:15],m[15:17]))
import random import datetime t = datetime.datetime.now() m = eval(input('输入随机抽点人数:')) with open('D:/实验六数据文件data5.txt', encoding = 'utf-8') as f:
data = f.readlines() list = [] for i in range(m): x = random.choice(data) list.append(x) data.remove(x) filename = t.strftime('%Y%m%d') + '.txt' with open(filename, "w+", encoding="utf-8") as f: f.writelines(list) f.seek(0) print(f.read())
with open('D:/实验六数据文件data5_1.txt','r',encoding='utf-8')as f: data=f.readlines() for i in data: i.strip("\n") import datetime t=datetime.datetime.now() filename=t.strftime('%Y%m%d')+'txt' print(f"{'抽点开始':=^40}") import random while True: n=int(input('输入随机抽点人数:')) sample=random.sample(data,n) for i in sample: data.remove(i) with open(filename, 'a+', encoding='utf-8') as f: for i in sample: print(i) f.write(i) if n==0: print(f"{'抽点结束':=^40}") break
这篇关于实验六的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南