Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jackfrued
GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/公开课/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example04.py
3078 views
1
from random import randint, sample
2
3
4
def generate():
5
"""生成一组随机号码"""
6
red_balls = [x for x in range(1, 34)]
7
selected_balls = sample(red_balls, 6)
8
selected_balls.sort()
9
selected_balls.append(randint(1, 16))
10
return selected_balls
11
12
13
def display(balls):
14
"""输出一组双色球号码"""
15
for index, ball in enumerate(balls):
16
print(f'{ball:0>2d}', end=' ')
17
if index == len(balls) - 2:
18
print('|', end=' ')
19
print()
20
21
22
num = int(input('机选几注: '))
23
for _ in range(num):
24
display(generate())
25
26