SAKURA-QiQi

导航

实验6

task3
# Created on 刘杰的iPad.
f1=open('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'1'<=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

 

 task5_1

import random

n = int(input('输入随机抽点人数:'))

with open('实验6/data5.txt', 'r', encoding='utf-8')as f:
    data = random.sample(f.readlines(), n)

import datetime

t = datetime.date.today()
filename = t.strftime('%Y%m%d') + '.txt'

with open(f'实验6/{filename}', 'w+', encoding='utf-8')as f:
    f.writelines(''.join(data).rstrip('\n'))
    f.seek(0)
    print(''.join(f.readlines()))

 

 task5_2

# Created on 刘杰的iPad.
f1=open('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'1'<=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

 

posted on 2022-05-25 07:00  QiQi-sakura  阅读(10)  评论(2编辑  收藏  举报