K
K
Kuzya2018-02-03 19:28:53
Python
Kuzya, 2018-02-03 19:28:53

How can this problem be effectively solved?

Good day. While reading M. Dawson's book "Programming in Python" I stumbled upon a problem that is given at the end of the chapter:
"But the task is more complicated. Write a game algorithm in pseudocode in which a random number from 1 to 100 is guessed by a person, and a computer guesses. Before proceeding to the solution, think about what the optimal guessing strategy should be.If the pseudocode algorithm is successful, try to implement the game in Python."
Help build a guessing algorithm, please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ant2015, 2018-02-03
@N_kuzya

Create 2 variables min and max and assign them 1 and 100 respectively. In the loop, ask the user to enter a number from 1 to 100 and assign it to a variable, and end the loop when the user's input is a number in the desired range. Then, in a loop, randomly generate a number x from min to max, and check with a guessed user. If x is less than the specified one, then min is assigned to x, if more, then x is assigned to max. If the numbers are equal, end the loop and display congratulations.
The idea is so!

D
Denis Knyazev, 2018-02-03
@axaxa_man

Binary search

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question