how to count the number of guesses in python

Solutions on MaxInterview for how to count the number of guesses in python by the best coders in the world

showing results for - "how to count the number of guesses in python"
Luigi
23 Jun 2020
1from random import randint
2guesses = 0
3randomNum = (randint(0,100))
4numPlayer = 0
5while (numPlayer!=randomNum):
6    numPlayer = int(input("Guess the number(0-100)"))
7    if (numPlayer>randomNum) : 
8        print "It's -"  
9    elif (numPlayer<randomNum) : print("It's +")
10    guesses=guesses+1
11
12print ("Well done you guessed my number in %d guesses" % guesses)