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)
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值