- 生成双色球和大乐透代码:
import randomdef gen_union_lotto(nums: int):"""随机生成N个双色球:param nums::return:"""union_list = []for i in range(0, nums):data = []for data_ in range(0, 6):random_num = random.randint(1, 33)while random_num in data:random_num = random.randint(1, 33)if random_num not in data:data.append(random_num)random_ = random.randint(1, 16)data.append(random_)union_list.append(data)for union in union_list:print(f'生成的双色球红区:{union[0:6]}:蓝区:{union[6]}')return union_listdef gen_super_lotto(nums: int):lotto_list = []for i in range(0, nums):data = []for key in range(0, 5):random_num = random.randint(1, 35)while random_num in data:random_num = random.randint(1, 35)if random_num not in data:data.append(random_num)down_data = []for key in range(0, 2):bb = random.randint(1, 12)while bb in down_data:bb = random.randint(1, 12)down_data.append(bb)data.append(bb)lotto_list.append(data)for lotto in lotto_list:print(f'大乐透前区为:{lotto[0:5]},后区:{lotto[5:7]}')# defif __name__ == '__main__':gen_super_lotto(5)gen_union_lotto(5)
- 使用方法:
gen_super_lotto(n) : n表示生成几组大乐透数据
gen_union_lotto(n) : n表示生成几组双色球数据
大家有需要的,点波关注评论分享!