python随机双色球

# -*- coding: utf-8 -*-
# @Time : 2021/7/5 8:31
# @Author : Lise Peng
# @Email : 1277055871@qq.com
# @File : 双色球.py
# @Software: PyCharm



# 红球33个,蓝球16个,且不能重复,红球和蓝球从小到大排列


import random
import colorama


def findSmallest(arr):
# 将列表中的第一个数值赋值给smallest
smallest = arr[0]
# 将第一个值的索引作为最小值的索引赋给smallest_index
smallest_index = 0
for i in range(1, len(arr)):
# 对列表arr中的元素进行一一对比
if arr[i] < smallest:
smallest = arr[i]
smallest_index = i
return smallest_index


def selectionSort(arr):
newArr = []
for i in range(len(arr)):
# 列表中存在多少字符,就会调用多少次findSmallest arr = x_list中的数量
smallest = findSmallest(arr)
# 每一次都把findSmallest里面的最小值删除并存放在新的数组newArr中
newArr.append(arr.pop(smallest))
return newArr


#red_s1为list类型,此时需要将list转换为string类型
# 将获取到的随机列表赋值给临时变量red_s1
red_s1 = selectionSort(random.sample([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,31,32,33],6))
# 将red_s1中的列表数据,依次存入到red_s2中
red_s2 = [str(i) for i in red_s1]

# ''.join(red_s2) 使用.join()的方法,将red_s2(list)转换为string类型并输出打印
print(colorama.Fore.RED + ' '.join(red_s2),end=' ')



bule_s1 = selectionSort(random.sample([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],1))
bule_s2 = [str(i) for i in bule_s1]
print(colorama.Fore.BLUE + ''.join(bule_s2))


posted @ 2021-07-06 09:38  江南一棵松  阅读(257)  评论(0)    收藏  举报