python石头剪刀布循环_Python石头布剪刀游戏(循环一定条件)
我做了一个简单的石头-布-剪刀程序,我需要在这个程序中添加一定的条件。。我必须让
用户不停地玩,直到用户或计算机连续赢了两次以上。我试图从中找出答案,但不幸地找不到。。在
首先我尝试了gameOver = False
playerScore = 0
computerScore = 0
并添加
^{pr2}$
并将playerScore+=1添加到if语句中。
但不起作用…
任何建议都会有所帮助,我们将不胜感激。。干杯!
这是我的代码。import random
import sys
def main():
player = input("Enter your choice in number (rock 1 / paper 2 / scissors 0) :")
if (player == 0):
player = "scissors"
elif (player == 1):
player = "rock"
elif (player == 2):
player = "paper"
else:
print("Invalid Input Quitting...")
sys.exit(0)
computer = random.randint(0,2)
if (computer == 0):
computer = "scissors"
elif (computer == 1):
computer = "rock"
elif (computer == 2):
computer = "paper"
if (player == computer):
print("Player is ",player, "Computer is ",computer," You Draw!")
elif (player == "rock"):
if (computer == "paper"):
print("Player is ",player, "Computer is ",computer," You Lost!")
else:
print("Player is ",player, "Computer is ",computer," You Win!")
elif (player == "paper"):
if (computer == "rock"):
print("Player is ",player, "Computer is ",computer," You Win!")
else:
print("Player is ",player, "Computer is ",computer," You Lost!")
elif (player == "scissors"):
if (computer == "rock"):
print("Player is ",player, "Computer is ",computer," You Lost!")
else:
print("Player is ",player, "Computer is ",computer," You Win!")