根据学习手动输入一注双色球选择程序,结合random写的一段自动生成5注机选大乐透的尝试
import random
n = 0
while n < 5: #判断直到生成5注时停止:生成+打印
red_ball = []
blue_ball = []
while len(red_ball) < 5:
m = random.randint(1,35)
num = "%02d"%m #为了显示的时候对齐,自动在小于10的个位数前面的十位补0
if num in red_ball:
continue
else:
red_ball.append(num)
red_ball.sort()
while len(blue_ball) < 2:
m = random.randint(1,12)
num = "%02d"%m
if num in blue_ball:
continue
else:
blue_ball.append(num)
blue_ball.sort()
print(n+1,":",red_ball," ",blue_ball)
n += 1