我正在做岩石,纸,剪刀。岩石剪刀卡在while循环
经过3次胜利或失败后,我希望它离开while循环,但它一直在运行。
##################
# import modules #
##################
from random import randint
# Declaration of variables #
pcCounter, counter = 0, 0
choice = ""
pc = 0
################
# Main program #
################
print("Welcome to Dags Rock,Paper,Scissors")
print("We will be playing a best out of 5")
choice = input("Select rock, paper or scissors")
while counter != 3 or pcCounter != 3:
if choice == "rock" or choice == "Rock":
pc = randint(1,3)
if pc == 1:
print("You have tied")
choice = input("Enter either rock, paper or scissors")
elif pc == 2:
print("You have lost, Paper beats rock")
pcCounter += 1
choice = input("Enter either rock, paper or scissors")
else:
print("You have won, rock beats scissors")
counter += 1
choice = input("Enter either rock, paper or scissors")
elif choice == "paper" or choice == "Paper":
pc = randint(1,3)
if pc == 1:
print("You have won, paper beats rock")
counter += 1
choice = input("Enter either rock, paper or scissors")
elif pc == 2:
print("You have tied")
choice = input("Enter either rock, paper or scissors")
else:
print("You have lost, scissors beats paper")
pcCounter += 1
choice = input("Enter either rock, paper or scissors")
else:
pc = randint(1,3)
if pc == 1:
print("You have lost, rock beats scissors")
pcCounter += 1
choice = input("Enter either rock, paper or scissors")
elif pc == 2:
print("You have won, scissors beats paper")
Counter += 1
choice = input("Enter either rock, paper or scissors")
else:
print("You have tied")
choice = input("Enter either rock, paper or scissors")
#Checks if you won or lost
if counter == 3:
print("Congratz you won :)")
else:
print("Darn you lost :(")enter code here
没错这就是问题所在,感谢一吨,只是一个初学者的错误,我想:d –
注意,有,是由Shivin指出了一个额外的错误:在一个地方,你'计数器+ = 1'而比'counter + = 1'。案例很重要,所以这是行不通的。 –