本文实例讲述了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程序设计有所帮助。
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
Latest Articles by Author
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
Latest Issues
-
2025-03-27 19:34:19
-
2025-03-27 19:31:56
-
2025-03-27 19:27:19
-
2025-03-27 19:25:41
-
2025-03-27 19:24:28