CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/番外篇/code/test03.py
Views: 729
1
from random import randint, sample
2
3
# 初始化备选红色球
4
red_balls = [x for x in range(1, 34)]
5
# 选出六个红色球
6
selected_balls = sample(red_balls, 6)
7
# 对红色球进行排序
8
selected_balls.sort()
9
# 添加一个蓝色球
10
selected_balls.append(randint(1, 16))
11
# 输出选中的随机号码
12
for index, ball in enumerate(selected_balls):
13
print('%02d' % ball, end=' ')
14
if index == len(selected_balls) - 2:
15
print('|', end=' ')
16
print()
17