Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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<randomNum) : print("It's +")
    guesses=guesses+1

print ("Well done you guessed my number in %d guesses" % guesses)
Source by codereview.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #count #number #guesses #python
ADD COMMENT
Topic
Name
6+6 =