# 1、写一个生成双色球号码的一个程序,生成的号码写到文件里面
# # 中奖号码由6个红色球号码和1个蓝色球号码组成
# # 篮球范围:01-16 1个
# # 红球范围:01-33 6个
# def swq(num):
# random.ranint(1,16)
# #tikti.txt
# 篮球:xx 红球号码是xx 01 08 09 12 13 19
# 篮球:xx 红球号码是xx 01 08 09 12 13 19
import random
def seq():
red_num = [] #红球
while len(red_num)!=6:
# 1 - 33
num = random.randint(1,33)
num = str(num).zfill(2)
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
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()