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

实验6

作者:互联网

任务3

 1 def is_valid(x):
 2     a,b,c = set(x),set("1234567890X"),set()
 3     if (a|b)-b!=c or len(x)!=18:return False
 4     return True
 5 with open("data3_id.txt","r",encoding="UTF-8") as f:
 6     data2=[id1.split(",") for id1 in f.read().split("\n")[:-1]]
 7 data3=list(filter(lambda x:is_valid(x[1]),data2))
 8 data4=sorted(data3,key=lambda x:x[1][6:14])
 9 for id3 in data4:
10     print(id3[0]+f",{id3[1][6:10]}-{id3[1][10:12]}-{id3[1][12:14]}")

 

 

 

 

 

任务5_1

 1 import random
 2 import datetime
 3 with open("data5.txt", "r+", encoding="UTF-8") as f:
 4     list1, x = f.readlines(), 1
 5     list2 = [id1.strip("\n") for id1 in list1]
 6 x = eval(input())
 7 list3 = random.sample(list2, x)
 8 date1 = (datetime.datetime.now()).strftime("%y%m%d")
 9 with open(f"{date1}.txt", "w+", encoding="UTF-8") as g:
10     for id2 in range(len(list3)):
11         print(list3[id2])
12         g.write(list3[id2]+"\n")

 

 

 

任务5_2

 1 import random
 2 import datetime
 3 with open("data5.txt", "r+", encoding="UTF-8") as f:
 4     list1, x = f.readlines(), 1
 5     list2 = [id1.strip("\n") for id1 in list1]
 6 while x != 0:
 7     x = eval(input())
 8     list3 = random.sample(list2, x)
 9     list2 = list(set(list2)-set(list3))
10     date1 = (datetime.datetime.now()).strftime("%y%m%d")
11     with open(f"{date1}.txt", "w+", encoding="UTF-8") as g:
12         for id2 in range(len(list3)):
13             print(list3[id2])
14             g.write(list3[id2]+"\n")

 

 

标签:set,datetime,id2,list3,list2,实验,id1
来源: https://www.cnblogs.com/rua-mua/p/16285979.html