其他分享
首页 > 其他分享> > 实验六

实验六

作者:互联网

def is_valid(id):
   if len(id[1]) == 18 and (id[1][:-1].isdigit() and id[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
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')

 

标签:encoding,datetime,实验,txt,d2,id,d1
来源: https://www.cnblogs.com/AkieUp07/p/16308882.html