这里是你的通告内容

春生

Be humble, communicate clearly, and respect others.

双色球

双色球

要求

每注投注号码由6个红色球号码和1个蓝色球号码组成。红色球号码从1--33中选择;蓝色球号码从1--16中选择

代码

import random

number =set()
num = input('请输入要产生多少注:').strip()

if num.isdigit():
    while len(number)!=int(num):
        red_ball = ' '.join(sorted(random.sample([str(i).zfill(2)for i in range(1,34)],6)))
        bule_ball =' ' .join(sorted(random.sample([str(i).zfill(2) for i in range(1, 17)], 1)))
        two_ball = '红球:%s  蓝球:%s\n'%(red_ball,bule_ball)
        number.add(two_ball)
else:
    print('请输入数字!')

with open('双色球.txt','a+',encoding='utf-8')as fw:
    fw.writelines(number)

代码

import random
all_red_ball = [str(i).zfill(2) for i in range(1, 34)]
all_blue_ball = [str(i).zfill(2) for i in range(1, 17)]
def gen_seq():
    blue = random.choice(all_blue_ball)
    red = random.sample(all_red_ball,6)
    red = ' '.join(red)
    return '红球:%s 篮球:%s'%(red,blue)

all_seq=set()
num = int(input('请输入要产生多少条双色球:').strip())
while len(all_seq) != num:
    res = gen_seq()+'\n'
    all_seq.add(res)
with open('passwords.txt','w',encoding='utf-8') as fw:
    fw.writelines(all_seq)
posted @ 2020-10-28 19:05  PythonAV  阅读(233)  评论(0编辑  收藏  举报