|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
程序:
import random
result = random.sample(range(1, 34), k=6)
special = random.sample(range(1, 17), k=1)
print("result:" , result)
print("special:" , special)
red = random.sample(range(1, 34), 6)
blue = random.randint(1, 16)
print("开奖结果是:", *red)
print("特别号码是:", blue)
上面是我写的,下面是答案
运行结果:
result: [25, 20, 30, 27, 14, 21]
special: [7]
开奖结果是: 13 18 33 1 5 25
特别号码是: 9
为什么答案里的结果没有中括号呢?
因为 sample 得出来的是列表,你直接打印列表了,你可以加个 * 把列表解包成多个位置参数:
- import random
- result = random.sample(range(1, 34), k=6)
- special = random.sample(range(1, 17), k=1)
- print("result:" , *result) # 加个 *
- print("special:" , *special) # 加个 *
复制代码
|
|