用random随机生成一组数字
直接贴上代码:
# -*- coding: UTF-8 -*-
__author__ = 'bo.chen'
'''
彩票生成机 双色球
'''
from random import choice
# 随机生成一张双色球彩票
def getAcaipiao():
redball = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33"]
blueball = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16"]
count = 0
bcount = 0
redno = []
blueno = []
#33选5
while count < 6:
temp = choice(redball)
if temp in redno:
continue
else:
redno.append(temp)
count = count + 1
blueno.append(choice(blueball))
#对红球数组进行升序排列
redno.sort()
return redno + blueno
# 随机生成一张大乐透彩票
def getBcaipiao():
redball = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33","34","35"]
blueball = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
count = 0
bcount = 0
redno = []
blueno = []
#33选5
while count < 5:
temp = choice(redball)
if temp in redno:
continue
else:
redno.append(temp)
count = count + 1
while bcount<2:
temp=choice(blueball)
if temp in blueno:
continue
else:
blueno.append(temp)
bcount=bcount+1
#对红球数组进行升序排列
redno.sort()
blueno.sort()
return redno + blueno
print u"双色球号码:"
print getAcaipiao()
print u"大乐透号码:"
print getBcaipiao()
input= raw_input("")
print input