实验六
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-10SpringBoot 内部方法调用,事务不起作用的原因及解决办法
- 2024-11-10独立开发者 5 个月,月收入赶超北京工资,我的一点心得
- 2024-11-09程序员 SEO 系列:如何找到更多搜索关键词?
- 2024-11-09为何选择Spring AI Alibaba开发智能客服平台?
- 2024-11-09Sentinel不同的流控效果资料详解
- 2024-11-09Sentinel配置限流资料:新手入门教程
- 2024-11-09Sentinel配置限流资料详解
- 2024-11-09Sentinel熔断规则配置资料详解
- 2024-11-08Sentinel熔断规则配置资料详解
- 2024-11-08Sentinel限流资料入门教程