实验六
def is_valid(x):
if len(x[1])==18 and (x[1][:-1].isdigit() and x[1][-1] in '0123456789X'):
return True
return False
with open('data3_id.txt','r',encoding='utf-8') as f:
id_name=[(i[:2],i[3:].strip('\n')) for i in f.readlines()[1:]]
result=list(filter(is_valid,id_name))
result.sort(key=lambda x:int(x[1][6:14]))
for i in result:
print(f"{i[0]},{i[1][6:10]}-{i[1][10:12]}-{i[1][12:14]}")
import random n=int(input("输入随机抽点人数:")) with open('data5.txt','r',encoding='utf=8') as f: list=f.readlines() list2=random.sample(list,n) with open("20220522.txt",'w+',encoding='utf=8') as f: for i in list2: print(i) f.write(i+'\n')
import random print(f"{'抽点开始':=^40}") n=int(input("输入随机抽点人数:")) with open('data5.txt','r+',encoding='utf=8') as f: list=f.readlines() while n!=0: list1=random.sample(list,n) for i in list1: print(i) list.remove(i) with open("20220522.txt","a+",encoding='utf=8') as f: for i in list1: f.write(i+'\n') n=int(input("输入随机抽点人数:")) print(f"{'抽点结束':=^40}")