how to count the number of guesses in python 1

how to count the number of guesses in python

from random import randint
guesses = 0
randomNum = (randint(0,100))
numPlayer = 0
while (numPlayer!=randomNum):
    numPlayer = int(input("Guess the number(0-100)"))
    if (numPlayer>randomNum) : 
        print "It's -"  
    elif (numPlayer

Here is what the above code is Doing:
1. We import the randint function from the random module.
2. We set the number of guesses to 0.
3. We generate a random number between 0 and 100.
4. We ask the player to guess a number.
5. If the player's guess is less than the random number, we print "It's +".
6. If the player's guess is more than the random number, we print "It's -".
7. If the player's guess is equal to the random number, we print "Well done you guessed my number in %d guesses" % guesses.

Similar Posts