作业要求:
每注投注号码由6个红色球号码和1个蓝色球号码组成。红色球号码从1--33中选择;蓝色球号码从1--16中选择
代码范例
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)