实验6
def is_valid(x): ls = [str(i) for i in range(0, 10)] ls.append('X') if len(x) < 18: return False for a in range(len(x)): if x[a] not in ls: return False break if a == len(x) - 1: return True with open('data3_id.txt', 'r', encoding='utf-8') as f: data = f.read().split('\n') data1 = [] data2 = [] a = 0 for i in range(1, len(data)): x = data[i].split(',') if is_valid(x[1]): data1.append(x) for i in data1: data2.append(i[1][6:14] + str(a)) a += 1 data2.sort() for i in range(len(data1)): n = int(data2[i][8:]) print('{},{}-{}-{}'.format(data1[n][0], data2[i][0:4], data2[i][4:6], data2[i][6:8]))
import random x=list(range(1,81)) n=int(input('请输入随机抽点人数:')) with open('data5.txt','r',encoding='utf-8') as f: data=f.readlines() d1=[] for i in data: d1.append(i.strip('\n')) d2=random.sample(d1,n) for i in d2: print(i) import datetime t=datetime.datetime.now() f1=t.strftime('%Y%m%d')+'.txt' with open(f1,'w',encoding='utf-8') as f: for i in d2: f.write(i+'\n')
import random x=list(range(1,81)) with open('data5.txt','r',encoding='utf-8') as f: data=f.readlines() d1=[] for i in data: d1.append(i.rstrip('\n')) import datetime t=datetime.datetime.now() f1=t.strftime('%Y%m%d')+'.txt' print('{:=^50}'.format('抽点开始')) while True: n=int(input('请输入随机抽点人数:')) if n==0: print('{:=^50}'.format('抽点结束')) break d2=(random.sample(d1,n)) for i in d2: print(i) with open(f1,'a',encoding='utf-8') as f: for i in d2: f.write(i+'\n')