Python题目:双色球,用函数实现机选和手选

def fun1():
    print('欢迎进入双色球!==============')
    red_ball = []
    while True:
        red = int(input('请输入红色球的球号:'))
        if red in red_ball or red>33 or red<1:
            print('请重新输入')
            continue
        else:
            red_ball.append(red)
            if len(red_ball) == 6:
                break

    while True:
        blue = int(input('请输入蓝球的球号:'))
        if 1 <= blue <= 16:
            print('您选择的红色球号是:{}'.format(red_ball))
            print('您选择的蓝色球号是:{}'.format(blue))
            break
        else:
            print('重新输入')
def fun2():
    import random
    num1 = [i for i in range(1, 34)]
    red_balls = random.sample(num1, 6)
    print('机选红球是:',red_balls)
    num2=[i for i in range(1,17)]
    blue_balls=random.choice(num2)
    print('机选蓝球是:',blue_balls)

while True:
    num = int(input('请问是要机选还是手选(1机选/0手选):'))
    if num == 0:
        fun1()
        break
    elif num == 1:
        fun2()
        break
    else:
        print('输入有误!请重新输入')

你可能感兴趣的:(Python每日练习题,python)