python第一章作业:双色球彩票 选购程序

1.先让用户依次选择6个红球,再选择2个蓝球,最后统一打印用户选择的球号。

2.确保用户不能选择重复的,选择的数不能超出范围。

red_ball_box = [] # 选号池
count_red=0
while count_red<5: # 选5个红球
    user_select_red = int(input('select red ball:')) # 用户输入
    if user_select_red > 32 or user_select_red<1: # 范围限定
        print('only can select between 1-32')
        continue
    elif user_select_red in red_ball_box: # 禁止重复
        print('number %s is alread exist in red ball list' %user_select_red)
        continue
    red_ball_box.append(user_select_red) # 接受输入加进列表
    count_red += 1

blue_ball_box = []
count_blue = 0
while count_blue<2: # 选2个蓝球
    user_select_blue = int(input('select blue ball:')) # 用户输入
    if user_select_blue > 16 or user_select_blue<1: # 范围限定
        print('only can select between 1-16')
        continue
    elif user_select_blue in blue_ball_box: # 禁止重复
        print('number %s is alread exist in blue ball list' %user_select_blue)
        continue
    blue_ball_box.append(user_select_blue) # 接受输入加进列表
    count_blue += 1
print('\nred ball:%s' %red_ball_box)
print('blue ball:%s\nGOOD LUCK' %blue_ball_box)
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页