Python numbers game reverse -


so have make "game" on python think of number , tries guess number. have tell if it's higher or lower number guessed , continue there. far have doing need have no idea how make python remember numbers it's guessed. if tell guess number between 1 , 10 , guesses 7, it's high guesses 4 , it's low might guess , 8. can't have guess number higher 7 since said it's lower already. there way make remember that? here's code:

from random import randrange def lowhigh():     l = input ("please input low number range.")     numl = eval(l)     h = input ("please input high number range.")     numh = eval(h)     guess = randrange(1,numh + 1)     print (guess)     while true:         ask = input("is number correct? y yes or n no.")         if ask == 'y':             print("yay! guessed right!")             break         else:             loworhigh = input ("is number high or low? h high, l low.")             if loworhigh == 'h':                 guess = randrange(numl,guess-1)                 print(guess)             else:                 guess = randrange(guess+1,numh)                 print(guess) 

you can use 2 different numbers indicate lowest , highest guesses.

when computer guesses number , higher actual number, can make highest = number.

same way when computer guesses number , lower actual number, can make lower = number.

and each time take random number between these 2 lowest , highest number only.

the code -

from random import randrange def lowhigh():     l = input ("please input low number range.")     numl = eval(l)     h = input ("please input high number range.")     numh = eval(h)     lowest = l     highest = h     while true:         guess = randrange(lowest,highest+1)         print (guess)         ask = input("is number correct? y yes or n no.")         if ask == 'y':             print("yay! guessed right!")             break         else:             loworhigh = input ("is number high or low? h high, l low.")             if loworhigh == 'h':                highest = guess - 1             else:                lowest = guess 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -