Python记分牌
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python记分牌相关的知识,希望对你有一定的参考价值。
我正在尝试创建一个简单的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
答案
如果你只想让它在循环运行后等待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')
以上是关于Python记分牌的主要内容,如果未能解决你的问题,请参考以下文章