# 实验六

1 def is_valid(x):
2 2         data=x
3 3         if len(data)!=18:
4 4             print(False)
5 5         else:
6 6             if ord(data[-1])==88 or 48<=ord(data[-1])<=57 :
7 7                 print(True)
8 8             else:
9 9                 print(False)

 1 1 with open('data3_id.txt', 'r', encoding='utf-8') as f:
3  3 data=[line.strip().split(',') for line in data]
4  4 ans=[]
5  5 def isvalid(id):
6  6     if len(id)!=18: return False
7  7     else:
8  8         for i in id:
9  9             if '0'<=i<='9'or i=='X':continue
10 10             return False
11 11         return True
12 12 for i in range(1,len(data)):
13 13     if(isvalid(data[i][1])):
14 14         ans.append([data[i][0],data[i][1][6:10]+'-'+data[i][1][10:12]+'-'+data[i][1][12:14]])
15 15 ans.sort(key=lambda x:x[1])
16 16 print(f'{data[0][0]},{data[0][1]}')
17 17 for line in ans:
18 18     print(f'{line[0]},{line[1]}')
19 复制代码

 1  1 import random
2  2 import datetime
3  3 with open('data5(1).txt', 'r', encoding='utf-8') as f:
5  5 data=[line.strip().split(',') for line in data]
6  6 book=[0]*len(data)
7  7 n=eval(input('输入随机抽点人数:'))
8  8 ans=[]
9  9 cnt=0
10 10 while cnt<5:
11 11         x=random.randint(0,len(data))
12 12         if book[x]:continue
13 13         cnt+=1;book[x]=1
14 14         ans.append(data[x])
15 15 t=datetime.datetime.now()
16 16 filename = t.strftime('%Y%m%d') + '.txt'
17 17 for line in ans:
18 18     print(line[0])
19 19 with open(filename,'w',encoding='utf-8') as f:
20 20     for line in ans:
21 21         f.write(str(line[0]+'\n'))

 1 1 with open('data5(1).txt','r',encoding='utf-8')as f:
3  3     data2=[]
4  4     for i in data1:
5  5         data2.append(i.split('\t'))
6  6 import random
7  7 import datetime
8  8 while True:
9  9   n=int(input('输入随机抽点人数：'))
10 10   if n==0:
11 11       break
12 12   data3=[]
13 13   data4=[]
14 14   while len(data3)<n:
15 15       if data2[random.randint(0,len(data2)-1)] not in data3:
16 16           data3.append(data2[random.randint(0,len(data2)-1)])
17 17   for i in data3:
18 18       print(','.join(i))
19 19       data4.append(','.join(i)+'\n')
20 20   t=datetime.datetime.now()
21 21   filename=t.strftime('%Y%m%d')+'.txt'
22 22   with open (filename,'w',encoding='utf-8')as f:
23 23     f.writelines(','.join(data4))
24 复制代码

posted @ 2022-05-19 00:08  是个f个人  阅读(19)  评论(3编辑  收藏  举报