实验6

2022/5/22 23:06:53

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

def is_valid(id):
  if len(id) !=18:
return False
  try:
   for i in id:
    if i =='x'
      continue
elif  type (eval(i))==int
  continue
else:return False
except:return False 
return True


import csv
a=[]
with open('date3_id.txt','r',encoding='utf-8')as f:
   f_reader=csv.DictReader(f)
   for line in f_reader:
     x=line.get('身份证号码')
     if is_valid(x)==False
       continue
     else:
       line['身份证号码']=line['身份证号码'][6:10]+'-'+line['身份证号码'][10:12]+'-'+line['身份证号码'][12:14]
       a.append(line)
b=sorted(a,key=lambda i :i['身份证'])
for a in b:
  print(f"{a['姓名']},{a['身份证号码']}")

import random
import datetime
b=[]
with open('data6.txt','r',encoding='utf-8') as f:
    data=f.read().strip('\n')
    a=date.split('\n')
    for i in a:
        b.append(i.split('\t'))
x=random.sample(b,eval(input('输入随机抽点个数:')))
t=datetime.datetime.now()
with open(t.strftime('%Y%m%d')+'.txt','w',encodiing='utf-8') as f:
    for i in x:
        f.write('\t'.join(i))
        f.write('\n')
        print('\t'.noin(i))

import random
import datetime

b=[]
with open('data6.txt','r',encoding='utf-8')as f:
   date=f.read().strip('\n')
   a=date.split('\n')
   for i in a:
     b.append(i.split('\t'))

   t=datetime.datetime.now()
   with open(t.strftime('%Y%m%d')+'_txt,'a',encoding='utf-8')as f:
      print("{:=∧30}''.format('抽点开始'))
      y=1
      while y !=0:
        y=eva(input('输入随机抽点个数:'))
        x=random.sample(b,y)
        for i in x:
          b.remove(i)
          f.write('\t'.join(i))
          print('\t'.join(i))
      print("{:=∧30}".format('抽点结束'))

 



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


扫一扫关注最新编程教程