• 老男孩python学习阶段性作业双色球选购


    作业:双色球选购

    1 双色球(假设一共八个球,6个红球,球号1-32、2个蓝球,球号1-16)
    2 确保用户不能重复选择,不能超出范围
    3 用户输入有误时有相应的错误提示
    4 最后展示用户选择的双色球的号码

    第一次提交代码:

    #! /user/bin/env python
    # -*- coding:utf-8 -*-
    print('Welcome to 小猿圈 lottery station')
    redcount = 1
    redlist = []
    while redcount<=6:
        redball = input('[%s] Select red ball:'%(redcount))
        if (int(redball)<1 or int(redball)>32):
            print('only can  select n between 1-32')
        elif(int(redball) in redlist):
            print('number %s is already exsit in red ball list' %(redball))
        else:
            redlist.append(int(redball))
            redcount = redcount + 1
    bluecount = 1
    bluelist = []
    while bluecount<=2:
        blueball = input('[%s] Select blue ball:'%(bluecount))
        if (int(blueball) < 1 or int(blueball) > 16):
            print('only can  select n between 1-16')
        elif(int(blueball) in bluelist):
            print('number %s is already exsit in blue ball list' %(blueball))
        else:
            bluelist.append(int(blueball))
            bluecount = bluecount + 1
    print('''Red ball: %s 
    Blue ball:%s
    Good Luck.
    ''' %(redlist,bluelist,))
    

    第二次提交代码:

    #! /user/bin/env python
    # -*- coding:utf-8 -*-
    print('Welcome to 小猿圈 lottery station')
    count = 1
    red_count = 1
    blue_count = 1
    red_list = []
    blue_list = []
    while count <= 8:
        if red_count <= 6:
            red_ball = input('[%s] Select red ball:' % (red_count,))
            if red_ball.isdigit():
                red_ball = int(red_ball)
                if red_ball < 1 or red_ball > 32:
                    print('only can  select n between 1-32')
                elif red_ball in red_list:
                    print('number %s is already exist in red ball list' % (red_ball,))
                else:
                    red_list.append(red_ball)
                    red_count += 1
                    count += 1
            else:
                print('请输入数字')
                continue
        else:
            if blue_count <= 2:
                blue_ball = input('[%s] Select blue ball:' % (blue_count,))
                if blue_ball.isdigit():
                    blue_ball = int(blue_ball)
                    if blue_ball < 1 or blue_ball > 16:
                        print('only can  select n between 1-16')
                    elif blue_ball in blue_list:
                        print('number %s is already exist in blue ball list' % (blue_ball,))
                    else:
                        blue_list.append(blue_ball)
                        blue_count += 1
                        count += 1
                else:
                    print('请输入数字')
                    continue
    print('''Red ball: %s 
    Blue ball:%s
    Good Luck.
    ''' % (red_list, blue_list,))
    

    最终版

    #! /user/bin/env python
    # -*- coding:utf-8 -*-
    print('Welcome to 小猿圈 lottery station')
    red_count = 1
    blue_count = 1
    red_list = []
    blue_list = []
    while True:
        if red_count <= 6:
            red_ball = input('[%s] Select red ball:' % (red_count,))
            if red_ball.isdigit():
                red_ball = int(red_ball)
                if red_ball < 1 or red_ball > 32:
                    print('only can  select n between 1-32')
                elif red_ball in red_list:
                    print('number %s is already exist in red ball list' % (red_ball,))
                else:
                    red_list.append(red_ball)
                    red_count += 1
            else:
                print('请输入数字')
                continue
        else:
            if blue_count <= 2:
                blue_ball = input('[%s] Select blue ball:' % (blue_count,))
                if blue_ball.isdigit():
                    blue_ball = int(blue_ball)
                    if blue_ball < 1 or blue_ball > 16:
                        print('only can  select n between 1-16')
                    elif blue_ball in blue_list:
                        print('number %s is already exist in blue ball list' % (blue_ball,))
                    else:
                        blue_list.append(blue_ball)
                        blue_count += 1
                else:
                    print('请输入数字')
                    continue
            else:
                break
    print('''Red ball: %s 
    Blue ball:%s
    Good Luck.
    ''' % (red_list, blue_list,))
    
  • 相关阅读:
    placement new小结
    template template parameter 模板模板参数
    windows下创建和删除软链接
    gcc下载地址
    map的erase函数小结
    typedef函数指针
    宏定义条件编译中使用多条件
    关于c++模板特例化测试
    tolua使用
    c++多态
  • 原文地址:https://www.cnblogs.com/zhanglongfei/p/11581447.html
Copyright © 2020-2023  润新知