Home  >  Article  >  Backend Development  >  Python随机生成彩票号码的方法

Python随机生成彩票号码的方法

WBOY
WBOYOriginal
2016-06-10 15:17:412277browse

本文实例讲述了Python随机生成彩票号码的方法。分享给大家供大家参考。具体如下:

前些日子在淘宝上买了一阵子彩票,每次都是使用淘宝的机选,每次一注。后来觉得不如自己写一个机选的程序有意思

1. xuanhao.py文件

import random
def getResultStr(totalCount, resultCount):
  elements = [x + 1 for x in range(totalCount)]
  retStr = ''
  for i in range(resultCount):
    res = elements[random.randint(0,len(elements)-1)]
    elements.remove(res)
    retStr += ' ' + str(res)
  return retStr

2. shuangseqiu.py文件

import xuanhao
print xuanhao.getResultStr(33, 6)
print xuanhao.getResultStr(16, 1)

3. daletou.py文件

import xuanhao
print xuanhao.getResultStr(35, 5)
print xuanhao.getResultStr(12, 2)

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn