zoukankan      html  css  js  c++  java
  • 老男孩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,))
    
  • 相关阅读:
    魔改版BBR
    termux 开启 sshd
    Basic berkeley socket functions
    mosh
    XOR 加密
    指定so动态链接库连接器
    UTF8 UTF16 之间的互相转换
    MySQL C API概述
    C JAVA你可能不知道的那些编程细节
    虚拟内存
  • 原文地址:https://www.cnblogs.com/zhanglongfei/p/11581447.html
Copyright © 2011-2022 走看看