5.18 实践6

def is_vaild(x):
    ture_list = ['0','1','2','3','4','5','6','7','8','9','X',]
    num = 0
    for id in x:
        num+=ture_list.count(id)
    if num!=18:
        return False
    return True


with open('data3_id.txt','r',encoding='utf-8')as f:
    data = f.readlines()
    data.pop(0)
    id_list = []
    for i in data:
        id_list.append(i.strip('\n'))
    ture_id_list = []
    for item in id_list:
        if is_vaild(item[3:]) == True:
            ture_id_list.append(item)
    # print(ture_id_list)
    ture_id_list.sort(key=lambda x: int(x[9:16]))
    # print(ture_id_list)
    for item in ture_id_list:
        print(f'{item[:3]}{item[9:16]}')

 

import datetime
import random
import time
with open('data5.txt','r',encoding='utf-8')as f:
    data = f.readlines()
    # print(data)
    student_liist = []
    for item in data:
        student_liist.append(item.strip('\n'))
    print(student_liist)
    n = eval(input(':'))
    name = random.sample(student_liist,n)
    for item in name:
        print(item)
    t = datetime.datetime.now()
    filename = t.strftime('%Y%m%d') + '.txt'
with open(filename,'w',encoding='utf-8')as f:
    for i in name:
        f.write(i+'\n')

 

import datetime
import random
import time
with open('data5.txt','r',encoding='utf-8')as f:
data = f.readlines()
# print(data)
student_liist = []
for item in data:
student_liist.append(item.strip('\n'))
student_liist1 = student_liist.copy()
print(f"{'开始抽点':=^40}")
while True:
n = eval(input('开始点名输入点名人数:'))
if n==0:
print(f"{'抽点结束':=^40}")
break
else:
name = random.sample(student_liist1, n)
for chou in name:
print(chou)
student_liist1.remove(chou)
t = datetime.datetime.now()
filename = t.strftime('%Y%m%d') + '.txt'
with open(filename, 'w', encoding='utf-8') as f:
for i in name:
f.write(i + '\n')

 

 

posted @ 2022-05-18 21:01  奈落——  阅读(13)  评论(3编辑  收藏  举报