Python-双色球
#“双色球总共是49个号,其中红号是33个就是从1到33号,选择6个,蓝号是16个,就是从1到16 号,选择1个 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)
本文来自博客园,作者:他还在坚持嘛,转载请注明原文链接:他还在坚持嘛 https://www.cnblogs.com/brf-test/p/12951132.html