我试图写一个游戏,玩家一选择一个数字,玩家二有五个猜测来猜它。如果他成功做到了,他赢了,如果没有,他就输了,一号球员赢了。在
所以我有代码,但是如果一号玩家选择了数字'3',玩家二号在他的任何一次行动中输入数字'3',它仍然显示玩家一获胜。在>>>
Player One enter you chosen number: 3
Player Two have a guess: 3
Player One wins.
>>>
这种情况也会发生:
^{pr2}$
另外,玩家2可以有任意多个回合,但应该只有5个。如果他超过这个数量,玩家1自动获胜。这是我的密码:(我不知道我错了。)def Game():
Guess = 0
NumberOfGuesses = 0
NumberToGuess = int(input("Player One enter you chosen number: "))
while NumberToGuess < 1 or NumberToGuess > 10:
NumberToGuess = int(input("Not a valid choice, please enter another number: "))
while Guess != NumberToGuess and NumberOfGuesses < 5:
Guess = int(input("Player Two have a guess: "))
NumberOfGuesses = NumberOfGuesses + 1
if Guess == NumberToGuess:
print("Player One wins.")
else:
print("Player Two wins.")
Game()