Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
from random import*
SecretNumber=randint(0,12)
Guess=int(input("Please enter Guess: "))

NumberofGuesses=0



   
        
while Guess != SecretNumber:
            NumberofGuesses=NumberofGuesses+1

      
            if Guess>SecretNumber:
               print("Please insert a smaller number")
               break
               

            if Guess<SecretNumber:
                print("Please insert a bigger number")
                break
                
                
            
             
                
               
               
              


print("Number of Guesses: {0}".format(NumberofGuesses))


What I have tried:

I tried using the While loop but I dont know why it isnt working
Posted
Updated 4-Apr-16 21:00pm

1 solution

Because it does nothing to modify the Guess. Isn't it obvious? You have to input guess in each iteration. Practically, it's useful to add some condition to break the loop immediately on the user request. :-)

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900