python/公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example04.py
2024-12-04 00:04:56 +08:00

25 lines
568 B
Python

from random import randint, sample
def generate():
"""生成一组随机号码"""
red_balls = [x for x in range(1, 34)]
selected_balls = sample(red_balls, 6)
selected_balls.sort()
selected_balls.append(randint(1, 16))
return selected_balls
def display(balls):
"""输出一组双色球号码"""
for index, ball in enumerate(balls):
print(f'{ball:0>2d}', end=' ')
if index == len(balls) - 2:
print('|', end=' ')
print()
num = int(input('机选几注: '))
for _ in range(num):
display(generate())