zoukankan      html  css  js  c++  java
  • 双色球

    作业:双色球选购
    1 双色球(假设一共八个球,6个红球,球号1-32、2个蓝球,球号1-16)
    2 确保用户不能重复选择,不能超出范围
    3 用户输入有误时有相应的错误提示
    4 最后展示用户选择的双色球的号码
    #红色球选择范围清单
    list_red = list(range(1,33))
    #蓝色球选择范围清单
    list_blue = list(range(1,17))
    #红色球选择清单
    select_red = []
    #蓝色球选择清单
    select_blue = []
    #红色球选择次数
    num_red = 0
    #蓝色球选择次数
    num_blue = 0
    #判断选择次数
    while num_red < 6:
        num_red += 1
        red = int(input('[%s]select red ball:'%num_red))
        # blue = int(input('[%s]select blue ball:'%num_blue))
        while red not in list_red:
            print('only can select number between 1-32')
            red = int(input('[%s]select red ball:' % num_red))
        while red in select_red:
            print('number %s is already exist in red ball list'%red)
            red = int(input('[%s]select red ball:' % num_red))
        else:
            select_red.append(red)
    while num_blue < 2:
        num_blue += 1
        blue = int(input('[%s]select blue ball:'%num_blue))
        while blue not in list_blue:
            print('only can select number between 1-16')
            blue = int(input('[%s]select blue ball:'%num_blue))
        while blue in select_blue:
            print('number %s is already exist in red ball list'%blue)
            blue = int(input('[%s]select blue ball:'%num_blue))
        else:
            select_blue.append(blue)
    print('Red ball:%s'%select_red)
    print('Blue ball:%s'%select_blue)
    print('Good Luck.')
    def select_ball(ball):
        #最后选择好的球清单
        ball_list = []
        #选择球的次数
        num_ball = 0
        if ball == 'red':
            #球号码的选择范围清单
            list_ball = list(range(1, 33))
            max = 32
            #球号码的选择次数上限
            num_max = 6
        elif ball == 'blue':
            list_ball = list(range(1,17))
            max = 16
            num_max = 2
            pass
        while num_ball < num_max:
            num_ball += 1
            select_ball= int(input('[%s]select %s ball:'%(num_ball,ball)))
            while select_ball not in list_ball:
                print('only can select number between 1-%s'%max)
                select_ball = int(input('[%s]select %s ball:'%(num_ball,ball)))
            while select_ball in ball_list:
                print('number %s is already exist in %s ball list'%(select_ball,ball))
                select_ball = int(input('[%s]select %s ball:'%(num_ball,ball)))
            else:
                ball_list.append(select_ball)
        print('%s ball:%s' %(ball,ball_list))
    select_ball('red')
    select_ball('blue')
    print('Good Luck.')
  • 相关阅读:
    【xinsir】githook之precommit分享
    node进程一些信号的意义
    ES6篇
    Webpack4篇
    Node篇
    Vuex篇
    WebStorage篇
    HTML5篇
    html5语义化标签大全
    emmet语法
  • 原文地址:https://www.cnblogs.com/thanos-ryan/p/13247106.html
Copyright © 2011-2022 走看看