Python随机生成彩票号码的方法
作者:卢温禾 时间:2023-10-13 15:25:39
本文实例讲述了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程序设计有所帮助。
标签:Python,随机,生成,方法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于JS实现的随机数字抽签实例
2024-04-16 09:27:23
PHP实现上传文件并存进数据库的方法
2023-07-03 21:35:14
python中利用numpy.array()实现俩个数值列表的对应相加方法
2022-08-26 01:49:25
js multiple全选与取消全选实现代码
2024-04-28 10:19:36
js对象内部访问this修饰的成员函数示例
2024-04-18 10:47:04
Python的字典和列表的使用中一些需要注意的地方
2023-01-09 02:03:52
sql server 复制表从一个数据库到另一个数据库
2024-01-18 23:51:55
python矩阵转换为一维数组的实例
2023-09-13 18:34:10
Python解释器以及PyCharm的安装教程图文详解
2021-04-09 11:56:32
![](https://img.aspxhome.com/file/2023/6/71386_0s.jpg)
Python元素集合的列表切片
2023-08-08 23:08:57
![](https://img.aspxhome.com/file/2023/3/121383_0s.jpg)
Python urlopen()函数 示例分享
2022-08-15 01:00:58
python基于Node2Vec实现节点分类及其可视化示例详解
2022-04-16 06:49:33
django 使用全局搜索功能的实例详解
2023-01-26 05:56:56
Perl操作系统环境变量的脚本代码
2022-12-27 12:17:22
css2.1实现多重背景和边框效果
2010-06-23 19:02:00
![](https://img.aspxhome.com/file/UploadPic/20106/23/01-35s.jpg)
Anaconda和Pycharm的安装配置教程分享
2022-10-22 07:12:30
![](https://img.aspxhome.com/file/2023/6/90916_0s.png)
python实现爬取百度图片的方法示例
2021-11-22 00:46:04
让复杂导航设计变得简单
2008-01-07 11:50:00
![](https://img.aspxhome.com/file/UploadPic/20081/7/200817122654620s.jpg)
利用Python yagmail三行代码实现发送邮件
2021-10-16 08:39:04
![](https://img.aspxhome.com/file/2023/7/99677_0s.png)
Pyinstaller打包Scrapy项目的实现步骤
2022-05-01 18:07:02
![](https://img.aspxhome.com/file/2023/6/112786_0s.png)