python模拟双色球大乐透生成算法

    每天练习一段python代码,健康生活一辈子。晚上下班没事,打开电脑继续编写python代码!今天分享的一个是大家熟悉的双色球彩票的游戏,根据这个进行写的一个python算法,代码精简,肯定有bug,哪里不足的,可以交流学习!

     

# -*- coding: UTF-8 -*-
# 68喜科技 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

   运行,即可:

   

posted @ 2018-07-22 20:38  圆柱模板  阅读(2482)  评论(0编辑  收藏  举报