There is a task:
The player selects a random number from 1 to 100, which the computer must guess. Before you begin, think about how you guessed it. If everything goes well, try coding the game.
My code is:
import random
num = int(input('Your number: '))
numC = random.randint(1, 100)
tries = 1
while numC != num:
numC = random.randint(1, 100)
if numC > num:
print(numC, 'Less')
numC = random.randint(1, numC)
else:
print(numC, 'More')
numC = random.randint(numC, 100)
tries += 1
print(numC, 'Computer guessed your number with', tries, 'tries')
This works, but I don’t think it works the way the author wanted.
How to make this number of the intended program used with fewer attempts? I know this is about reducing the frames of a random generator, but I don’t know how to do this without using an infinite number of variables.
source
share