实验六

2022/5/24 23:21:22

本文主要是介绍实验六,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

def is_valid(x):
    ls=[str(i) for i in range(0,10)]
    ls.append('X')
    if len(x)<18:
        return False
    for a in range(len(x)):
        if x[a] not in ls:
            return False
            break
    if a==len(x)-1:
        return True
with open('data3_id.txt','r',encoding='utf-8')as f:
    data=f.read().split('\n')
data1=[]
data2=[]
a=0
for i in range(1,len(data)):
    x=data[i].split(',')
    if is_valid(x[1]):
        data1.append(x)
for i in data1:
    data2.append(i[1][6:14]+str(a))
    a+=1
data2.sort()
for i in range(len(data1)):
    n=int(data2[i][8:])
    print('{},{}-{}-{}'.format(data1[n][0],data2[i][0:4],data2[i][4:6],data2[i][6:8]))

with open('data5.txt','r',encoding='utf-8')as f:
    data1=f.read().split('\n')
    data2=[]
    for i in data1:
        data2.append(i.split('\t'))
import random
import datetime
while True:
  n=int(input('输入随机抽点人数:'))
  if n==0:
      break
  data3=[]
  data4=[]
  while len(data3)<n:
      if data2[random.randint(0,len(data2)-1)] not in data3:
          data3.append(data2[random.randint(0,len(data2)-1)])
  for i in data3:
      print(','.join(i))
      data4.append(','.join(i)+'\n')
  t=datetime.datetime.now()
  filename=t.strftime('%Y%m%d')+'.txt'
  with open (filename,'w',encoding='utf-8')as f:
    f.writelines(','.join(data4))

 



这篇关于实验六的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程