# 七乐彩投注号码范围为01~30,
# 七乐彩每期从30个号码中开出7个基本号码和1个特别号码作为中奖号码,
# 七乐彩玩法即是竞猜开奖号码中的7个基本号码和1个特别号码,顺序不限
import random
# 生成机选的号码
def makeRandomNum():# 红色球1-30# 蓝色球 1-30seq = [i for i in range(1, 31)] # 生成1到30元素的lista = random.sample(seq, 7) # 获取7个随机数a.sort() # 排序seq = [i for i in range(1, 31)] # 生成1到30元素的listb = random.sample(seq, 1) # 获取1个随机数b.sort() # 排序return a + b# 生成中红色球和蓝色球的个数,两个参数都是7位符合要求的列表
def getPrizeNum(prize_list, choose_list):# 红色球判断red_num = 0blue_num = 0for i in choose_list[0:7]:if i in prize_list[0:7]:red_num += 1print("红色球中奖号有",i)for j in choose_list[7:]:if j in prize_list[7:]:blue_num += 1print("蓝色球中奖号有", j)return red_num, blue_numdef judge_prize(red_num, blue_num):if red_num == 7:print("恭喜中一等奖")if red_num == 6:if blue_num == 1:print("恭喜中2等奖")elif blue_num == 0:print("恭喜中3等奖")if red_num == 5:if blue_num == 1:print("恭喜中4等奖")elif blue_num == 0:print("恭喜中5等奖")if red_num == 4:if blue_num == 1:print("恭喜中6等奖")elif blue_num == 0:print("恭喜中7等奖")# 生成中奖号码
prize_list = makeRandomNum()
print("本次中奖的号码为", prize_list)
# 购买的彩票号码
buy_list = makeRandomNum()
print("此次机选的号码为", buy_list)
red_num, blue_num = getPrizeNum(prize_list, buy_list)
print("红色球数量为", red_num, " 蓝色球中奖数量为", blue_num)judge_prize(red_num, blue_num)