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

WBOY
Release: 2016-06-10 15:17:41
Original
2278 people have browsed it

本文实例讲述了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
Copy after login

2. shuangseqiu.py文件

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

3. daletou.py文件

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template