So I have to make a \"game\" on python were I think of a number and it tries to guess the number. I have to tell it if it\'s higher or lower than the number it guessed and conti
You can use two different numbers to indicate the lowest and highest guesses.
When the computer guesses a number and its higher actual number, you can make the highest = that number.
Same way when the computer guesses a number and its lower than actual number, you can make the lower = that number.
And each time you take random number between these two lowest and highest number only.
The code would look like -
from random import randrange
def lowHigh():
l = input ("Please input the low number range.")
numl = eval(l)
h = input ("Please input the high number range.")
numh = eval(h)
lowest = l
highest = h
while True:
guess = randrange(lowest,highest+1)
print (guess)
ask = input("Is this number correct? y for yes or n for no.")
if ask == 'y':
print("Yay! I guessed right!")
break
else:
lowOrHigh = input ("Is this number too high or low? h for high, l for low.")
if lowOrHigh == 'h':
highest = guess - 1
else:
lowest = guess