Vote count:
0
I am trying to write a game where Player One picks a number and Player Two has 5 Guesses to guess it. If he manages to do so, he wins, if not, he losses and Player One wins.
So I have the code, but if for example Player one picks the number '3' and Player Two enters the number '3' on any of his goes, it still says Player One wins.
>>>
Player One enter you chosen number: 3
Player Two have a guess: 3
Player One wins.
>>>
This happens also:
>>>
Player One enter you chosen number: 5
Player Two wins.
Also, player two can have as many turns as he likes, but it should only be 5. If he passes that amount, Player One automatically wins. Here is my code: (I don't know here I went wrong.)
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()
asked 25 secs ago
Two Player Number Guessing Game - Python
Aucun commentaire:
Enregistrer un commentaire