Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: Python remove duplicate lines from a text file 
Python :: basic flask api 
Python :: pandas change period 
Python :: change xlabel python 
Python :: pandas series map 
Python :: python monitor directory for files count 
Python :: DIF_GCD 
Python :: python program to demonstrate scoping 
Python :: python loops 
Python :: python async await function 
Python :: how to find a specific word in a list python 
Python :: python find minimum date in list 
Python :: python how to iterate through a list of lists 
Python :: python invert colormap 
Python :: pytest create server 
Python :: python use variable name as string 
Python :: save jupyter notebook session 
Python :: block content 
Python :: input lstm 
Python :: how to create a network scanner in python 
Python :: nltk python how to tokenize text 
Python :: recursion python examples 
Python :: python trace table 
Python :: programmation orienté objet python 
Python :: how to create a subset of two columns in a dataframe 
Python :: all python versions 
Python :: turn string into operator python 
Python :: python gui framework 
Python :: python recursion example 
Python :: implement stack using list in python 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =