Python记分牌

问题描述 投票:0回答:1

我正在尝试创建一个简单的python记分牌。最后,我将添加按钮来增加和减少值。这是我目前的代码,如何让它打印“新游戏”并在有人获胜后5秒重启循环?

RedScore = 0
BlueScore = 0

while RedScore <= 5 and BlueScore <= 5:
    if RedScore == 5:
        print('RED WINS')
        break
    elif BlueScore == 5:
        print('BLUE WINS')
        break
    else:
        x = input("Who Scored? ")
        if x == 'Red':
            RedScore += 1
            print(RedScore)
        elif x == 'Blue':
            BlueScore += 1
            print(BlueScore)
        else:
            print('Bad Input')

另外,我想添加一个条件,如果你输入“REDRESET”,RED的分数将= 3

python raspberry-pi
1个回答
2
投票

如果你只想让它在循环运行后等待5秒钟,只需sleep 5秒钟。添加REDRESET就像拥有另一个elif一样简单

from time import sleep
while RedScore <= 5 and BlueScore <= 5:
    if RedScore == 5:
        print('RED WINS')
        sleep(5)
        RedScore = BlueScore = 0 
    elif BlueScore == 5:
        print('BLUE WINS')
        sleep(5)
        BlueScore = RedScore = 0
    else:
        x = input("Who Scored? ")
        if x == 'Red':
            RedScore += 1
            print(RedScore)
        elif x == 'Blue':
            BlueScore += 1
            print(BlueScore)
        elif x == 'REDRESET':
            RedScore = 3
        else:
            print('Bad Input')
© www.soinside.com 2019 - 2024. All rights reserved.