岩纸剪刀2球员
问题描述:
这是我的代码为我的2球员比赛。我遇到的问题无论如何,玩家2总是赢得并给予玩家2的分数。有人可以帮助我做到这一点,玩家1也可以赢得并获得分数。岩纸剪刀2球员
def vshuman():
score = [0,0]
while True:
while True:
user1_choice = input("Player 1 choose a weapon (1,2,3,4)")
user2_choice = input("Player 2 choose a weapon(1,2,3,4)")
if user1_choice == "1":
user1_choice == 1
break
if user2_choice == "1":
user2_choice == 1
break
elif user1_choice == "2":
user1_choice == 2
break
elif user2_choice == "2":
user1_choice == 2
break
elif user1_choice == "3":
user1_choice == 3
break
elif user2_choice == "3":
user2_choice == 3
break
elif user1_choice == "4":
user1_choice == 4
main()
elif user2_choice == "4":
user1_choice == 4
main()
if user1_choice == user2_choice:
print("Tie")
score[0] = score[0] + 1
score[1] = score[1] + 1
elif (user1_choice == 1 and user2_choice == 3):
print("Player 1 won")
score[0] = score[0] + 1
elif(user1_choice == 2 and user2_choice == 1):
print("Player 1 won")
score[0] = score[0] + 1
elif(user1_choice == 3 and user2_choice == 2):
print("Player 1 won")
score[0] = score[0] + 1
elif(user2_choice == 1 and user1_choice == 3):
print("Player 2 won")
score[1] = score[1] + 1
elif(user2_choice == 2 and user1_choice == 1):
print("Player 2 won")
score[1] = score[1] + 1
elif(user2_choice == 3 and user1_choice == 2):
print("Player 2 won")
score[1] = score[1] + 1
while True:
answer = input("Play another Round")
if answer == "y" or "Y":
print(" score: Player 1 -",score[0]," Player 2 -",score[1])
break
elif answer == "n" or "N":
print("I hope you enjoyed! Final score Player 1 -",score[0]," Player 2 -",score[1])
break
else:
print("y or n")
答
score = [0,0]
while 1:
c1 = int(input("Player 1 choose a weapon (1,2,3) : "))
c2 = int(input("Player 2 choose a weapon (1,2,3) : "))
if c1 == c2:
print('tie')
score[0] += 1
score[1] += 1
elif (c1 - 1) % 3 == c2 % 3:
print('Player 1 won')
score[0] += 1
else :
print('Player 2 won')
score[1] += 1
print(" score: Player 1 -",score[0]," Player 2 -",score[1])
answer = input("Play another Round (y/n) : ")
if answer.lower() != "y":
break
你调用'主()',但从来没有定义它。请提供[MVCE](http://stackoverflow.com/help/mcve)。 – L3viathan
哦,不,我有我的完整代码中的主这只是其中的一部分,我需要帮助 – Dennis
这就是为什么@ L3viathan要求一个MVCE。我们不能自己测试代码,问题本身就是* off-topic *。不欢迎寻求调试帮助的问题 – Li357