• 欢迎光临~

实验六

开发技术 开发技术 2022-05-24 次浏览

实验六

实验六

 

实验六

 

 

 

 

with open("data5.txt","r",encoding="utf-8") as f:
    d=f.readlines()
import random
n=int(input("输入随机抽点人数:"))
f1=set()
l=len(f1)
while l<n:
    f=random.randint(0,len(d))
    f1.add(d[f])
    l=len(f1)
for i in f1:
    print(i,end="")
with open("20220524.txt","w",encoding="utf-8") as f:
    for i in f1:
    

实验六

import random
list = []
while True:
    n = int(input("输入随机抽点人数: "))
    if n == 0:
        print('抽点结束')
        break
    else:
        with open("data5.txt", encoding="utf-8") as f:
            data = f.readlines()
        result = []
        for i in range(n):
            x = random.choice(data)
            result.append(x)
            data.remove(x)
        with open("20220525.txt", "w+", encoding="utf-8") as f:
            f.writelines(result)
            f.seek(0)
            print(f.read())
            lists =list+result
            with open("20220525.txt", "w", encoding="utf-8") as f:
                 f.writelines(list)

实验六

 

程序员灯塔
转载请注明原文链接:实验六
喜欢 (0)