#需求:双色球 红球是1-33 取6个 篮球1-16取1个,要求输入几就生成多少条
#seq函数产生双色球 main函数写条数 writer_file函数写文件
import random
def seq():
red_num=[]
while len(red_num)!=6:
num = random.randint(1,33)
num = str(num).zfill(2)#如果不到2位数前面加0
if num not in red_num:
red_num.append(num)
blue_num = str(random.randint(1,16)).zfill(2)
red_num_str = ' '.join(red_num)
res = "蓝球是%s,红球是%s
"%(blue_num,red_num_str)
return (res)
seq()
def write_file(l):
with open('seq.txt','w',encoding='utf-8') as fw:
fw.writelines(l)
def main():
all_res=[]
num = input("请输入你要产生多少条:").strip()
if num.isdigit():
num = int(num)
while num !=len(all_res):
res = seq()
if res not in all_res:
all_res.append(res)
else:
print("条数只能是整数")
write_file(all_res)
main()