# 实验6

1 list1 = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'X']
2 def is_valid(x):
3     if len(x) != 18 or x[-1] not in list1:
4         return False
5     else:
6         return True
7
8 with open('data3_id.txt', 'r', encoding='utf-8') as f:
10     list3=[line.rstrip('\n').split(',') for line in data]
11     list2 = []
12     list4=[]
13     for j in range(1, len(list3)):
14         y = list3[j]
15         l = y[1]
16         if is_valid(l) == True:
17             list2.append(data[j])
18     for p in range(len(list2)):
19         list4.append(list2[p][0:3]+list2[p][9:13]+'-'+list2[p][13:15]+'-'+list2[p][15:17])
20     list4.sort(reverse=True)
21     for k in list4:
22         print(k)

1 import random
2
3 x = int(input('输入你想抽点的人数:'))
4 with open('data5.txt', 'r', encoding='utf-8') as f:
5     lint = [line.strip('\n') for line in f.readlines()]
6     y = random.sample(lint, x)
7 with open('20220519.txt', 'w', encoding='utf-8') as g:
8     for i in y:
9         print(i)
10         g.write(i + '\n')

1 import random
2 with open('data5.txt', 'r', encoding='utf-8') as f:
3     lint = [line.strip('\n') for line in f.readlines()]
4 print(f"{'抽点开始':+^40}")
5 x=int(input('输入你想抽调的人数:'))
6 while x!=0:
7     y=random.sample(lint,x)
8     for i in y:
9         print(i)
10         lint.remove(i)
11     with open('20220519.txt', 'a+', encoding='utf-8') as g:
12         for i in y:
13             g.write(i + '\n')
14     x=int(input('输入你想抽点的人数:'))
15 print(f"{'抽调结束':+^40}")

posted @ 2022-05-19 11:40  气工吴旭  阅读(11)  评论(2编辑  收藏  举报