First page Back Continue Last page Overview Graphics

Improving the Guesses

So far the guesser always comes up with the same numbers.

To make the guesses less predictable, we will add or subtract a

random number from the values.

guess = (bottom + top) // 2

fuzzy = random.randint (1, max_number // 10)

factor = random.choice([-1,1])

if factor == 0:

guess = guess - fuzzy if guess - fuzzy > bottom else guess

else:

guess = guess + fuzzy if guess + fuzzy < top else guess