双色球小程序

 双色球规则:红球一共6组,每组从1-33中抽取一个,六个互相不重复。然后蓝球是从1-16中抽取一个数字,这整个组成的双色球。

import random

red_count = 0
red = []
blue_count = 0
blue = []
select = []
red_ball_count = 0
roll_red_ball = []
blue_ball_count = 0
roll_blue_ball = []

# 选号

while red_count < 6:
    red_ball = int(input("请选择红球号码:"))
    if red_ball in red:
        print("该红球号码已选择")
    elif red_ball > 0 and red_ball < 33:
        red.append(red_ball)
        red_count += 1
        print("已选择",red,"号红球")
    else:
        print("请输入正确的红球编号")

while blue_count < 1:
    blue_ball = int(input("请选择蓝球号码:"))
    if blue_ball in blue:
        print("该红球号码已选择")
    elif blue_ball > 0 and blue_ball < 16:
        blue.append(blue_ball)
        blue_count += 1
        print("已选择",blue,"号蓝球")
    else:
        print("请输入正确的蓝球编号")


select = red + blue
print("您选择的红色球:", red, "您选择的蓝色球:", blue)

# 摇号

# 红色号码
while red_ball_count < 6:
    red_ball_number = random.randint(1,33)
    if red_ball_number in roll_red_ball:
        pass
    else:
        roll_red_ball.append(red_ball_number)
        red_ball_count += 1
else:
    pass

    # 蓝色号码
    while blue_ball_count < 1:
        blue_ball_number = random.randint(1, 16)
        if blue_ball_number in roll_blue_ball:
            pass
        else:
            roll_blue_ball.append(blue_ball_number)
            blue_ball_count += 1
    else:
        pass

print("开奖号码为:", roll_red_ball, roll_blue_ball)


# 核对是否中奖

red_right = [r for r in red if r in roll_red_ball]
blue_right = [b for b in blue if b in roll_blue_ball]
print("中奖号码红色球:", red_right , "蓝色球:", blue_right)

 输出结果展示


image.png

你可能感兴趣的:(双色球小程序)