python -- 雙色球

ajax_beijing_java發表於2019-04-09
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/4/8 0008 17:48
# @Author  : cyx


# _*_ coding:utf-8 _*_
import random
def cyx_yiyi():
    qiu=[]
    while True:
        hong = random.randint(1,33)#產生一個隨機紅球
        if hong in qiu:
            continue#跳過本次迴圈
        qiu.append(hong)#把紅色號碼新增到列表
        if len(qiu)==6:
            break
    qiu.sort()
    lan=random.randint(1,16)#產生一個隨機籃球
    s=""
    for i in qiu:
        s=s+"%02d " %i#02d表示是2位數的整數,個數自動補0
    print (" 紅球 "+ s+"籃球 "+"%02d" %lan)

# for i in {1,2,3,4,5}:
for i in range(1, 6):
    # print (i)
    cyx_yiyi()

相關文章