python实现双色球_python中双色球

# 1、红色球6个,1,33,蓝色球1个,1-16

# 1、先从1,33之间取6个 random.sample([1,33],6)

# 2,再从1-16之间取1个 random.choice([1,16])

# 3、把双色球号码改成 红色球 01 02 03 04 05 06 蓝色球 07 的格式

# 4、读到文件的内容, 判断刚才产生的双色球是否在文件中

# 5、不在就写入

import random

FILE_NAME = 'seq.txt'

def op_file(content=None):

with open(FILE_NAME, 'a+', encoding='utf-8') as fw:

if content:

fw.write(content)

else:

fw.seek(0)

res = fw.read()

return res

def seq(num):

count = 0

while count < num:

b1 = [str(i).zfill(2) for i in range(1, 34)] # 产生一个01,02- 33的list

b2 = [str(i).zfill(2) for i in range(1, 17)] # 产生一个01,02- 33的list

red = random.sample(b1, 6) # 返回是一个list

red.sort() # 排序

blue = random.choice(b2)

red_str = ' '.join(red) # '01 02 03 04 05 06'

result = "红色球:%s 蓝色球:%s\n" % (red_str, blue)

all_ball = op_file() # 获取文件内容

if result not in all_ball:

op_file(result) # 写入

count += 1

def seq2(num):

count = 0

while count < num:

red_str = ' '.join(sorted(random.sample([str(i).zfill(2) for i in range(1, 34)], 6))) # 返回是一个list

blue = random.choice([str(i).zfill(2) for i in range(1, 17)])

result = "红色球:%s 蓝色球:%s\n" % (red_str, blue)

if result not in op_file():

op_file(result) # 写入

count += 1

seq2(20)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值