实验六

 1 def v(x):
 2     z=0
 3     if len(x)!=18:
 4         return False
 5     else:
 6         for i in x:
 7             if ord(i) < 48 or 87>=ord(i)>57 or ord(i)>88:
 8                 z+=1
 9         if z!=0:
10             return False
11         else:
12             return True
13 with open ('data3_id.txt','r',encoding='utf-8')as f:
14     o=[]
15     t=[]
16     a=f.readlines()
17     p=[]
18     n=[]
19     z=[]
20     for i in a:
21         p.append(i.split(','))
22     del p[0]
23     for i in p:
24         o.append(i)
25         i[1]=i[1].replace('\n','')
26     for i in p:
27         if v(i[1]):
28             t.append(o[p.index(i)])
29     for i in t:
30         n.append(int(i[1][6:13]))
31         z.append([i[0],i[1][6:10],'-',i[1][10:12],'-',i[1][11:13]])
32     no=[]
33     n1=[]
34     u=0
35     z1=[]
36     for i in n:
37         n1.append(i)
38     while u<7:
39         no.append(min(n))
40         del n[n.index(min(n))]
41         u+=1
42     for i in no:
43         z1.append(z[n1.index(i)])
44     z1[4]=z[4]
45     for i in z1:
46         print(i[0],i[1],i[2],i[3],i[4],i[5])

 

 1 with open ('data5.txt ','r',encoding='utf-8')as f:
 2     a=f.readlines()
 3 import random
 4 x=eval(input('输入抽点人数'))
 5 b=[]
 6 
 7 for i in random.sample(a, x):
 8     print(i)
 9     a.remove(i)
10     b.append(i)
11 from datetime import datetime
12 p = str(datetime.now())[0:4] + str(datetime.now())[5:7] + str(datetime.now())[8:11] + '.txt'
13 with open(p, 'w', encoding='utf-8') as f:
14     for i in b:
15         f.write(i)

 

 1 with open ('data5.txt ','r',encoding='utf-8')as f:
 2     a=f.readlines()
 3 import random
 4 x=eval(input('输入抽点人数'))
 5 b=[]
 6 while x!=0:
 7     for i in random.sample(a, x):
 8         print(i)
 9         a.remove(i)
10         b.append(i)
11     from datetime import datetime
12     p = str(datetime.now())[0:4] + str(datetime.now())[5:7] + str(datetime.now())[8:11] + '.txt'
13     with open(p, 'a', encoding='utf-8') as f:
14         for i in b:
15             f.write(i)
16     x=eval(input('输入抽点人数'))
17     b=[]
18 else:
19     print('抽点结束')

 

posted @ 2022-05-22 10:41  pray4hell  阅读(9)  评论(3编辑  收藏  举报