实验6

f1=open('D:\\data3_id.txt','r')
list1,list3=[],[]
for i in f1.readlines():
    list1.append(i.strip().split(','))
def is_valid(x):
    if len(x)==18:
        for i in x:
            if '0'<=i<='9' or i=='X':
                return True
            else:
                return False
    else:
        return False
list2=list1[0];del list1[0]
print(','.join(list2))
for i in list1:
    y=i[1]
    if is_valid(y)==True:

        z=i[1][6:10]+'-'+i[1][11:12]+'-'+i[1][13:14]
        print(i[0]+','+z)
f1.close()

import random
f1=open('D:\\data5.txt','r')
list1=[]
for i in f1.readlines():
    list1.append(i.strip('\n'))
n=int(input('输入随机随机抽点人数:'))
x=random.sample(list1,n)
import datetime
t=datetime.datetime.now()
filename = t.strftime('%Y%m%d') + '.txt'
with open(t.strftime('%Y%m%d')+'.txt', 'w+', encoding = 'UTF-8') as f:
    w
    for i in x:
        print(i)
        f.write(i+'\n')
f1.close()

 

import random
f1=open('D:\\data5.txt','r')
list1=[]
for i in f1.readlines():
    list1.append(i.strip('\n'))
n=int(input('输入随机随机抽点人数:'))
x=random.sample(list1,n)
import datetime
t=datetime.datetime.now()
filename = t.strftime('%Y%m%d') + '.txt'
with open(t.strftime('%Y%m%d')+'.txt', 'w+', encoding = 'UTF-8') as f:
    while n!=0:

        for i in x:
            print(i)
            f.write(i+'\n')
        n=int(input('输入随机随机抽点人数:'))
        x=random.sample(list1,n)
f1.close()

 

posted @ 2022-05-24 20:15  李禹灼  阅读(6)  评论(3编辑  收藏  举报